TransactionStore is responsible for storing the state required to successfully complete an authentication transaction. The store relies on encrypted, stateless cookies to store the transaction state.
Overview
During the OAuth/OIDC authentication flow, the SDK needs to maintain state between the initial authorization request and the callback. TheTransactionStore manages this state using encrypted cookies.
Key Features:
- Stateless encrypted cookie storage
- Support for parallel authentication transactions
- PKCE code verifier storage
- Return URL preservation
- State parameter management
Constructor
Options
A 32-byte, hex-encoded secret used for encrypting transaction cookies.
Configuration options for the transaction cookie.
The prefix of the cookie used to store the transaction state.When
enableParallelTransactions is true, the cookie name will be {prefix}{state}. When false, the cookie name will be {prefix}.The sameSite attribute of the transaction cookie.Required to allow the cookie to be sent on the callback request.
The secure attribute of the transaction cookie.Default: depends on the protocol of the application’s base URL. If the protocol is
https, then true, otherwise false.The path attribute of the transaction cookie.
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.
The expiration time for transaction cookies in seconds.Default: 1 hour (3600 seconds).
Controls whether multiple parallel login transactions are allowed.
- When
true(default): Multiple transaction cookies can coexist for multi-tab support. Each transaction gets a unique cookie name based on the state parameter. - When
false: Only one transaction cookie is maintained at a time. Attempting to start a new transaction while one exists will be ignored.
Methods
save
The response cookies object to set the transaction cookie on.
The transaction state to save.
Optional request cookies to check for existing transactions. When provided and
enableParallelTransactions is false, will check for existing transaction cookies. When omitted, the existence check is skipped for performance optimization.Errorwhen transaction state is missing required state parameter
get
The request cookies object.
The state parameter from the authorization callback.
Returns the transaction state or
null if no transaction exists or the cookie is invalid/expired.delete
The response cookies object.
The state parameter identifying the transaction to delete.
deleteAll
The request cookies object.
The response cookies object.
getCookiePrefix
The transaction cookie prefix.
TransactionState Type
The PKCE code verifier used in the authorization request.
The response type used in the authorization request.
The state parameter passed to the authorization server for CSRF protection.
The URL to redirect to after successful login.
A string value used to associate a client session with an ID Token, and to mitigate replay attacks.
The maximum age of the authentication session.
The auth session ID for connect accounts flow.
The scope requested for this transaction.
The audience used for this transaction.
Example Usage
TheTransactionStore is typically used internally by the SDK, but you can access it if needed:
Parallel Transactions
WhenenableParallelTransactions is enabled (default), the SDK can handle multiple concurrent authentication flows. This is useful for:
- Multi-tab support: Users can initiate login in multiple browser tabs simultaneously
- Multiple authentication contexts: Different parts of your app can trigger separate auth flows
- Connect accounts: Users can connect additional accounts while authenticated
{prefix}{state}, where state is the OAuth state parameter.
Example: Multi-tab Login
Single Transaction Mode
If you disable parallel transactions:Security Considerations
-
Encryption: Transaction cookies are always encrypted using the
secretparameter. - Expiration: Transaction cookies have a limited lifetime (default 1 hour) to prevent stale transactions.
- State Parameter: The state parameter provides CSRF protection for the OAuth flow.
-
Secure Cookies: In production, transaction cookies should always use the
secureattribute. -
SameSite: The
laxSameSite attribute is required to allow the cookie to be sent on the callback request.
Best Practices
- Keep Default Settings: The default configuration is secure and suitable for most applications.
- Enable Parallel Transactions: Unless you have specific requirements, keep parallel transactions enabled for better user experience.
- Set Appropriate Expiration: The default 1-hour expiration is reasonable for most cases. Adjust based on your authentication flow requirements.
- Use HTTPS: Always use HTTPS in production to ensure cookies are transmitted securely.
- Cookie Path: Set the cookie path to the most restrictive scope needed for your authentication routes.