AbstractSessionStore is an abstract base class for implementing custom session stores. It provides the foundation for both stateless (cookie-based) and stateful (external store) session management.
Overview
The SDK provides two built-in implementations:- StatelessSessionStore: Stores the entire session in an encrypted cookie (default)
- StatefulSessionStore: Stores a session ID in a cookie and the session data in an external store
AbstractSessionStore to create custom session storage implementations.
Constructor
Options
string
required
A 32-byte, hex-encoded secret used for encrypting cookies.
boolean
default:true
A boolean indicating whether rolling sessions should be used or not.When enabled, the session will continue to be extended as long as it is used within the inactivity duration. Once the upper bound, set via the
absoluteDuration, has been reached, the session will no longer be extended.number
default:259200
The absolute duration after which the session will expire (in seconds).Once the absolute duration has been reached, the session will no longer be extended.Default: 3 days (259200 seconds).
number
default:86400
The duration of inactivity after which the session will expire (in seconds).The session will be extended as long as it was active before the inactivity duration has been reached.Default: 1 day (86400 seconds).
SessionDataStore
A custom session store implementation used to persist sessions to a data store.
SessionCookieOptions
The options for the session cookie.
string
default:"__session"
The name of the session cookie.
'strict' | 'lax' | 'none'
default:"lax"
The sameSite attribute of the session cookie.
boolean
The secure attribute of the session cookie.Default: depends on the protocol of the application’s base URL. If the protocol is
https, then true, otherwise false.string
default:"/"
The path attribute of the session cookie.
string
Specifies the value for the Domain Set-Cookie attribute. By default, no domain is set, and most clients will consider the cookie to apply to only the current domain.
boolean
The transient attribute of the session cookie. When true, the cookie will not persist beyond the current session.
Abstract Methods
These methods must be implemented by subclasses.get
RequestCookies | ReadonlyRequestCookies
required
The request cookies object.
Promise<SessionData | null>
Returns the session data or
null if no session exists.set
iat property on the session will be used to compute the maxAge cookie value.
RequestCookies | ReadonlyRequestCookies
required
The request cookies object.
ResponseCookies
required
The response cookies object.
SessionData
required
The session data to save.
boolean
Whether this is a new session.
delete
RequestCookies | ReadonlyRequestCookies
required
The request cookies object.
ResponseCookies
required
The response cookies object.
Protected Methods
These methods are available to subclasses.epoch
number
The current time in seconds since epoch.
calculateMaxAge
number
required
The time the session was created (seconds since epoch).
number
The maximum age of the session in seconds.
Public Properties
string
The secret used for encrypting cookies.
string
The name of the session cookie.
SessionDataStore | undefined
The custom session store implementation (if provided).
CookieOptions
The cookie configuration options.
SessionDataStore Interface
When implementing a custom session store, you must provide an object that implements theSessionDataStore interface:
get
string
required
The session ID.
Promise<SessionData | null>
Returns the session data or
null if no session exists.set
string
required
The session ID.
SessionData
required
The session data to save.
delete
string
required
The session ID.
deleteByLogoutToken
LogoutToken
required
The logout token containing
sub (user ID) and/or sid (session ID).Example: Custom Database Session Store
Example: Redis Session Store
SessionData Type
Best Practices
- Session Expiration: Implement proper TTL/expiration in your custom store to prevent stale sessions from accumulating.
- Error Handling: Implement proper error handling in your store methods. The SDK will catch errors and treat them as missing sessions.
- Performance: Consider implementing caching strategies for frequently accessed sessions.
- Security: Ensure your session store is properly secured and access is restricted.
-
Backchannel Logout: Implement
deleteByLogoutTokento support Auth0’s backchannel logout feature. - Cleanup: Implement a background job to clean up expired sessions from your store.