Customize cookie names
An application must use a cookie name that matches an existing deployment or routing convention.
Auth.js · Pipe
Auth.js lets you override names and options for its cookies through the cookies configuration. Unspecified values retain Auth.js defaults, while session-cookie contents depend on the JWT or database session strategy.
Auth.js stores session state in cookies and lets you override selected cookie names and options through the main configuration. Unspecified properties continue using Auth.js defaults; cookie security behavior depends on the URL and the configured options.
cookies?: Partial<CookiesOptions>;| Name | Type | Description |
|---|---|---|
cookies | Partial<CookiesOptions> | Partial cookie configuration; entries can override cookie names and options, with omitted values using Auth.js defaults. |
cookies in the Auth.js configuration to customize names or attributes for supported cookies.import NextAuth from "next-auth";
export const { handlers, auth } = NextAuth({
cookies: {
sessionToken: {
name: "app.session-token",
options: {
httpOnly: true,
sameSite: "lax",
path: "/",
secure: process.env.NODE_ENV === "production"
}
}
}
});Overrides the session cookie name while retaining explicit secure cookie attributes.
An application must use a cookie name that matches an existing deployment or routing convention.
A security review requires explicit cookie attributes such as HTTPS-only access or a defined same-site policy.
An adapter-backed application needs to understand what value is stored client-side.
The cookies option accepts a partial cookie configuration, allowing selected cookie names and options to be overridden. Any omitted options use Auth.js defaults.
Follow-up: What happens when only the cookie name is supplied? The remaining cookie settings are filled from the corresponding Auth.js defaults.
With a JWT strategy, Auth.js places an encrypted JWT in the session cookie by default. If an adapter is used, the default strategy changes to database sessions, where the cookie contains a session token instead.
Follow-up: How can JWT sessions still be selected with an adapter? Set session.strategy explicitly to "jwt".
The secure-cookie behavior restricts cookies to HTTPS URLs when enabled. Auth.js uses a less restrictive default for local http:// development URLs, but disabling the security behavior manually is not recommended.
Follow-up: Why might production and development need separate cookie policies? Custom cookie settings can bypass Auth.js’s dynamic policy, so the URL environment must be handled explicitly.
CookieOptionCookiesOptionssession.strategysessionTokencallbackUrlcsrfTokenpkceCodeVerifierstate