Skip to main content
The 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. The TransactionStore 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

string
required
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).
boolean
default:true
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

Saves the transaction state to an encrypted cookie.
ResponseCookies
required
The response cookies object to set the transaction cookie on.
TransactionState
required
The transaction state to save.
RequestCookies
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.
Throws:
  • Error when transaction state is missing required state parameter

get

Retrieves the transaction state from the encrypted cookie.
RequestCookies
required
The request cookies object.
string
required
The state parameter from the authorization callback.
Promise<TransactionState | null>
Returns the transaction state or null if no transaction exists or the cookie is invalid/expired.

delete

Deletes the transaction cookie for a specific state.
ResponseCookies
required
The response cookies object.
string
required
The state parameter identifying the transaction to delete.

deleteAll

Deletes all transaction cookies based on the configured prefix.
RequestCookies
required
The request cookies object.
ResponseCookies
required
The response cookies object.

getCookiePrefix

Returns the configured prefix for transaction cookies.
string
The transaction cookie prefix.

TransactionState Type

string
The PKCE code verifier used in the authorization request.
RESPONSE_TYPES
The response type used in the authorization request.
string
The state parameter passed to the authorization server for CSRF protection.
string
The URL to redirect to after successful login.
string
A string value used to associate a client session with an ID Token, and to mitigate replay attacks.
number
The maximum age of the authentication session.
string
The auth session ID for connect accounts flow.
string
The scope requested for this transaction.
string
The audience used for this transaction.

Example Usage

The TransactionStore is typically used internally by the SDK, but you can access it if needed:

Parallel Transactions

When enableParallelTransactions 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
Each transaction gets a unique cookie: {prefix}{state}, where state is the OAuth state parameter.

Example: Multi-tab Login

Single Transaction Mode

If you disable parallel transactions:
Only one transaction can be active at a time. If a user attempts to start a new login while one is in progress, the new attempt will be silently ignored with a console warning.

Security Considerations

  1. Encryption: Transaction cookies are always encrypted using the secret parameter.
  2. Expiration: Transaction cookies have a limited lifetime (default 1 hour) to prevent stale transactions.
  3. State Parameter: The state parameter provides CSRF protection for the OAuth flow.
  4. Secure Cookies: In production, transaction cookies should always use the secure attribute.
  5. SameSite: The lax SameSite attribute is required to allow the cookie to be sent on the callback request.

Best Practices

  1. Keep Default Settings: The default configuration is secure and suitable for most applications.
  2. Enable Parallel Transactions: Unless you have specific requirements, keep parallel transactions enabled for better user experience.
  3. Set Appropriate Expiration: The default 1-hour expiration is reasonable for most cases. Adjust based on your authentication flow requirements.
  4. Use HTTPS: Always use HTTPS in production to ensure cookies are transmitted securely.
  5. Cookie Path: Set the cookie path to the most restrictive scope needed for your authentication routes.