@auth0/nextjs-auth0
Version:
Auth0 Next.js SDK
100 lines (99 loc) • 3.92 kB
TypeScript
import type * as jose from "jose";
import * as cookies from "./cookies.js";
export interface TransactionState extends jose.JWTPayload {
nonce: string;
codeVerifier: string;
responseType: string;
state: string;
returnTo: string;
maxAge?: number;
}
export interface TransactionCookieOptions {
/**
* The prefix of the cookie used to store the transaction state.
*
* Default: `__txn_{state}`.
*/
prefix?: string;
/**
* The sameSite attribute of the transaction cookie.
*
* Default: `lax`.
*/
sameSite?: "strict" | "lax" | "none";
/**
* 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`.
*/
secure?: boolean;
/**
* The path attribute of the transaction cookie. Will be set to '/' by default.
*/
path?: string;
/**
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no
* domain is set, and most clients will consider the cookie to apply to only
* the current domain.
*/
domain?: string;
/**
* The expiration time for transaction cookies in seconds.
* If not provided, defaults to 1 hour (3600 seconds).
*
* @default 3600
*/
maxAge?: number;
}
export interface TransactionStoreOptions {
secret: string;
cookieOptions?: TransactionCookieOptions;
/**
* Controls whether multiple parallel login transactions are allowed.
* When false, only one transaction cookie is maintained at a time.
* When true (default), multiple transaction cookies can coexist for multi-tab support.
*
* @default true
*/
enableParallelTransactions?: boolean;
}
/**
* 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.
*/
export declare class TransactionStore {
private readonly secret;
private readonly transactionCookiePrefix;
private readonly cookieOptions;
private readonly enableParallelTransactions;
constructor({ secret, cookieOptions, enableParallelTransactions }: TransactionStoreOptions);
/**
* Returns the name of the cookie used to store the transaction state.
* The cookie name is derived from the state parameter to prevent collisions
* between different transactions.
*/
private getTransactionCookieName;
/**
* Returns the configured prefix for transaction cookies.
*/
getCookiePrefix(): string;
/**
* Saves the transaction state to an encrypted cookie.
*
* @param resCookies - The response cookies object to set the transaction cookie on
* @param transactionState - The transaction state to save
* @param reqCookies - 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
*/
save(resCookies: cookies.ResponseCookies, transactionState: TransactionState, reqCookies?: cookies.RequestCookies): Promise<void>;
get(reqCookies: cookies.RequestCookies, state: string): Promise<jose.JWTDecryptResult<TransactionState> | null>;
delete(resCookies: cookies.ResponseCookies, state: string): Promise<void>;
/**
* Deletes all transaction cookies based on the configured prefix.
*/
deleteAll(reqCookies: cookies.RequestCookies, resCookies: cookies.ResponseCookies): Promise<void>;
}