Skip to content

Commit 94bd7d0

Browse files
added docs
1 parent 3abe778 commit 94bd7d0

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

Diff for: EXAMPLES.md

+35
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- [`beforeSessionSaved`](#beforesessionsaved)
2525
- [`onCallback`](#oncallback)
2626
- [Session configuration](#session-configuration)
27+
- [Cookie Configuration](#cookie-configuration)
2728
- [Database sessions](#database-sessions)
2829
- [Back-Channel Logout](#back-channel-logout)
2930
- [Combining middleware](#combining-middleware)
@@ -626,6 +627,40 @@ export const auth0 = new Auth0Client({
626627
| absoluteDuration | `number` | The absolute duration after which the session will expire. The value must be specified in seconds. Default: `3 days`. |
627628
| inactivityDuration | `number` | The duration of inactivity after which the session will expire. The value must be specified in seconds. Default: `1 day`. |
628629

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+
629664
## Database sessions
630665

631666
By default, the user's sessions are stored in encrypted cookies. You may choose to persist the sessions in your data store of choice.

Diff for: README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ You can customize the client by using the options below:
137137
| appBaseUrl | `string` | The URL of your application (e.g.: `http://localhost:3000`). If it's not specified, it will be loaded from the `APP_BASE_URL` environment variable. |
138138
| secret | `string` | A 32-byte, hex-encoded secret used for encrypting cookies. If it's not specified, it will be loaded from the `AUTH0_SECRET` environment variable. |
139139
| signInReturnToPath | `string` | The path to redirect the user to after successfully authenticating. Defaults to `/`. |
140-
| session | `SessionConfiguration` | Configure the session timeouts and whether to use rolling sessions or not. See [Session configuration](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#session-configuration) for additional details. |
140+
| session | `SessionConfiguration` | Configure the session timeouts and whether to use rolling sessions or not. See [Session configuration](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#session-configuration) for additional details. Also allows configuration of cookie attributes like `domain`, `path`, `secure`, `sameSite`, `httpOnly`, and `transient`. If not specified, these can be configured using `AUTH0_COOKIE_*` environment variables. See [Cookie Configuration](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#cookie-configuration) for details. |
141141
| beforeSessionSaved | `BeforeSessionSavedHook` | A method to manipulate the session before persisting it. See [beforeSessionSaved](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#beforesessionsaved) for additional details. |
142142
| onCallback | `OnCallbackHook` | A method to handle errors or manage redirects after attempting to authenticate. See [onCallback](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#oncallback) for additional details. |
143143
| sessionStore | `SessionStore` | A custom session store implementation used to persist sessions to a data store. See [Database sessions](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#database-sessions) for additional details. |
@@ -147,6 +147,18 @@ You can customize the client by using the options below:
147147
| httpTimeout | `number` | Integer value for the HTTP timeout in milliseconds for authentication requests. Defaults to `5000` milliseconds |
148148
| enableTelemetry | `boolean` | Boolean value to opt-out of sending the library name and version to your authorization server via the `Auth0-Client` header. Defaults to `true`. |
149149

150+
## Session Cookie Configuration
151+
You can specify the following environment variables to configure the session cookie:
152+
```env
153+
AUTH0_COOKIE_DOMAIN=
154+
AUTH0_COOKIE_PATH=
155+
AUTH0_COOKIE_TRANSIENT=
156+
AUTH0_COOKIE_HTTP_ONLY=
157+
AUTH0_COOKIE_SECURE=
158+
AUTH0_COOKIE_SAME_SITE=
159+
```
160+
Respsective counterparts are also available in the client configuration. See [Cookie Configuration](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md#cookie-configuration) for more details.
161+
150162
## Configuration Validation
151163

152164
The SDK performs validation of required configuration options when initializing the `Auth0Client`. The following options are mandatory and must be provided either through constructor options or environment variables:

0 commit comments

Comments
 (0)