Sessions plugin for hapi. It relies on catbox, so you can use whatever storage for them that catbox provides.
await server.register([
{
plugin: require(`./hapi-sessions`),
options: {
expiresIn: 3 * 24 * 60 * 60 * 1000,
password: ``, // 32 symbol password should be passed
cache: `cache-name`
}
}
]);
expiresIn
TTL for the session cookie and the cache record.password
Passowrd for cookie encryption.cache
Cache name created withinserver.cache
.isSecure
,isHttpOnly
the same as in server.state options.
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.