|
24 | 24 | - [`beforeSessionSaved`](#beforesessionsaved)
|
25 | 25 | - [`onCallback`](#oncallback)
|
26 | 26 | - [Session configuration](#session-configuration)
|
| 27 | +- [Cookie Configuration](#cookie-configuration) |
27 | 28 | - [Database sessions](#database-sessions)
|
28 | 29 | - [Back-Channel Logout](#back-channel-logout)
|
29 | 30 | - [Combining middleware](#combining-middleware)
|
@@ -626,6 +627,40 @@ export const auth0 = new Auth0Client({
|
626 | 627 | | absoluteDuration | `number` | The absolute duration after which the session will expire. The value must be specified in seconds. Default: `3 days`. |
|
627 | 628 | | inactivityDuration | `number` | The duration of inactivity after which the session will expire. The value must be specified in seconds. Default: `1 day`. |
|
628 | 629 |
|
| 630 | +## Cookie Configuration |
| 631 | + |
| 632 | +You can configure session cookie attributes directly in the client options. These options take precedence over environment variables (`AUTH0_COOKIE_*`). |
| 633 | + |
| 634 | +```ts |
| 635 | +import { Auth0Client } from "@auth0/nextjs-auth0/server" |
| 636 | + |
| 637 | +export const auth0 = new Auth0Client({ |
| 638 | + session: { |
| 639 | + cookie: { |
| 640 | + domain: ".example.com", // Set cookie for subdomains |
| 641 | + path: "/app", // Limit cookie to /app path |
| 642 | + transient: true, // Make cookie transient (session-only, ignores maxAge) |
| 643 | + httpOnly: true, |
| 644 | + secure: process.env.NODE_ENV === "production", |
| 645 | + sameSite: "Lax", |
| 646 | + // name: 'appSession', // Optional: custom cookie name, defaults to '__session' |
| 647 | + }, |
| 648 | + // ... other session options like absoluteDuration ... |
| 649 | + }, |
| 650 | + // ... other client options ... |
| 651 | +}) |
| 652 | +``` |
| 653 | + |
| 654 | +**Cookie Options:** |
| 655 | + |
| 656 | +* `domain` (String): Specifies the `Domain` attribute. |
| 657 | +* `path` (String): Specifies the `Path` attribute. Defaults to `/`. |
| 658 | +* `transient` (Boolean): If `true`, the `maxAge` attribute is omitted, making it a session cookie. Defaults to `false`. |
| 659 | +* `httpOnly` (Boolean): Specifies the `HttpOnly` attribute. Defaults to `true`. |
| 660 | +* `secure` (Boolean): Specifies the `Secure` attribute. Defaults to `false` (or `true` if `AUTH0_COOKIE_SECURE=true` is set). |
| 661 | +* `sameSite` ('Lax' | 'Strict' | 'None'): Specifies the `SameSite` attribute. Defaults to `Lax` (or the value of `AUTH0_COOKIE_SAME_SITE`). |
| 662 | +* `name` (String): The name of the session cookie. Defaults to `__session`. |
| 663 | + |
629 | 664 | ## Database sessions
|
630 | 665 |
|
631 | 666 | By default, the user's sessions are stored in encrypted cookies. You may choose to persist the sessions in your data store of choice.
|
|
0 commit comments