Below is a breakdown of the SessionEngine object class generated while creating a new session engine instance. A single session engine can be shared across multiple HyperExpress.Server instances.
duration[Number]: Specifies the lifetime of sessions in milliseconds.- Default:
1000 * 60 * 30(30 Minutes)
- Default:
automatic_touch[Boolean]: Specifies whether active sessions should betouchedregardless of data changes upon each request.- Default:
true
- Default:
cookie[Object]: Specifies session cookie options.name[String]: Cookie Namedomain[String]: Cookie Domainpath[String]: Cookie Pathsecure[Boolean]: Adds Secure FlaghttpOnly[Boolean]: Adds httpOnly FlagsameSite[Boolean,'none','lax','strict']: Cookie Same-Site Preferencesecret[String]: Specifies secret value used to sign/authenticate session cookies.
- Note! a strong and unique string is required for
cookie.secret.
| Property | Type | Description |
|---|---|---|
middleware |
Function |
Middleware handler to be used with HyperExpress.use(). |
use(String: type, Function: handler): Binds a handler for specified operationtype.- Note you must use your own storage implementation in combination with available operations below.
- Supported Operations:
- [
read]: Must read and return session data as anObjectfrom your storage.- Parameters:
(Session: session) => {}. - Expects A
Promisewhich then resolves to anObjectorundefinedtype. - Required
- Parameters:
- [
touch]: Must update session expiry timestamp in your storage.- Parameters:
(Session: session) => {}. - Expects A
Promisewhich is then resolved toAnytype. - Required
- Parameters:
- [
write]: Must write session data and update expiry timestamp to your storage.- Parameters:
(Session: session) => {}.- You can use
session.storedto determine if you need toINSERTorUPDATEfor SQL based implementations.
- You can use
- Expects A
Promisewhich then resolves toAnytype. - Required
- Parameters:
- [
destroy]: Must destroy session from your storage.- Parameters:
(Session: session) => {}. - Expects A
Promisewhich then resolves toAnytype. - Required
- Parameters:
- [
id]: Must return a promise that generates and resolves a cryptographically random id.- Parameters:
() => {}. - Expects A
Promisewhich then resolves toStringtype. - Optional
- Parameters:
- [
cleanup]: Must clean up expired sessions from your storage.- Parameters:
() => {}. - Expects A
Promisewhich then resolves toAnytype. - Optional
- Parameters:
- [
- See
> [Session]for working with thesessionparameter.
cleanup(): Triggerscleanupoperation handler to delete expired sessions from storage.