1.0.3 • Published 8 years ago
hapi-sessions v1.0.3
hapi-sessions
Sessions plugin for hapi. It relies on catbox, so you can use whatever storage for them that catbox provides.
Example
await server.register([
{
plugin: require(`./hapi-sessions`),
options: {
expiresIn: 3 * 24 * 60 * 60 * 1000,
password: ``, // 32 symbol password should be passed
cache: `cache-name`
}
}
]);Options
expiresInTTL for the session cookie and the cache record.passwordPassowrd for cookie encryption.cacheCache name created withinserver.cache.isSecure,isHttpOnlythe same as in server.state options.
API
await request.session.get()– gets the session data, stored in cache.await request.session.set(value)– sets the session data.await request.session.addOrChange(value)– use only when the session data stored as an object. It merges passed object with stored in session one.request.sessionsCache– a link to a catbox policy with all the sessions. You can take the session id fromrequest.state.session.
The plugin has been made by a total rookie for personal purposes. Any critics are welcome.