From 469634cfeb063f527e531c8914d5b5622f49f3d0 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 21 Apr 2026 14:24:39 +0200 Subject: [PATCH 1/6] fix(configuration-reference): replace deprecated usage + small reorg --- .../en/reference/configuration-reference.mdx | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/content/docs/en/reference/configuration-reference.mdx b/src/content/docs/en/reference/configuration-reference.mdx index 2039bb4c8f594..d16420e4a635a 100644 --- a/src/content/docs/en/reference/configuration-reference.mdx +++ b/src/content/docs/en/reference/configuration-reference.mdx @@ -1228,24 +1228,24 @@ Set custom HTTP response headers to be sent in `astro dev` and `astro preview`.

Configures session storage for your Astro project. This is used to store session data in a persistent way, so that it can be accessed across different requests. -Some adapters may provide a default session driver, but you can override it with your own configuration. -See [the sessions guide](/en/guides/sessions/) for more information. +Some adapters may provide a default session driver, but you can override it with your own configuration: ```js title="astro.config.mjs" - { - session: { - // The name of the Unstorage driver - driver: 'redis', - // The required options depend on the driver - options: { - url: process.env.REDIS_URL, - }, - ttl: 3600, // 1 hour - } +import { defineConfig, sessionDrivers } from 'astro/config' + +export default defineConfig({ + session: { + driver: sessionDrivers.redis({ + // The options are driver-dependent and some may be required. + url: process.env.REDIS_URL + }), } +}) ``` +See [the sessions guide](/en/guides/sessions/) for more information. + ### session.driver

@@ -2505,4 +2505,3 @@ Font [variation settings](https://developer.mozilla.org/en-US/docs/Web/CSS/@font ```js variationSettings: "'xhgt' 0.7" ``` - From a1edc3ee68433d70b24e6260738d4ec8a72a2a1d Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 21 Apr 2026 14:45:32 +0200 Subject: [PATCH 2/6] fix(guides/sessions): show how to use runtime environment variables --- src/content/docs/en/guides/sessions.mdx | 38 ++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/content/docs/en/guides/sessions.mdx b/src/content/docs/en/guides/sessions.mdx index c18f1f6f7cbc3..fd3cec92c5c5d 100644 --- a/src/content/docs/en/guides/sessions.mdx +++ b/src/content/docs/en/guides/sessions.mdx @@ -35,18 +35,48 @@ import vercel from '@astrojs/vercel' export default defineConfig({ adapter: vercel() session: { - driver: sessionDrivers.redis({ - url: process.env.REDIS_URL + driver: sessionDrivers.lruCache({ + max: 800, }), } }) ``` +When you need to override options at runtime using environment variables, you can define the driver in a separate file and use the module as [entrypoint for the session driver](/en/reference/session-driver-reference/#entrypoint) in your configuration. + +The following example configures the Redis driver with runtime variables in a file located in your `src` directory: + +```ts title="src/session-driver.ts" +import type { SessionDriverConfig } from "astro"; +import { sessionDrivers } from "astro/config"; + +export default function (): SessionDriverConfig { + return sessionDrivers.redis({ + url: process.env.REDIS_URL, + }); +} +``` + +You can then reference this file as the driver entrypoint in your Astro configuration: + +```js title="astro.config.mjs" {7-9} +import { defineConfig, sessionDrivers } from 'astro/config' +import vercel from '@astrojs/vercel' + +export default defineConfig({ + adapter: vercel(), + session: { + driver: { + entrypoint: new URL('./src/session-driver.ts', import.meta.url), + } + } +}) +``` + - See [the `session` configuration option](/en/reference/configuration-reference/#session-options) for more details on setting a storage driver, and other configurable options. +See [the `session` configuration option](/en/reference/configuration-reference/#session-options) for more details on setting a storage driver, and other configurable options. - ## Interacting with session data The [`session` object](/en/reference/api-reference/#session) allows you to interact with the stored user state (e.g. adding items to a shopping cart) and the session ID (e.g. deleting the session ID cookie when logging out). The object is accessible as `Astro.session` in your Astro components and pages and as `context.session` object in API endpoints, middleware, and actions. From 2f8f5b0e3057b34820742f706847a73bf617fe43 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 21 Apr 2026 14:57:05 +0200 Subject: [PATCH 3/6] fix(configuration-reference): more links to highlight runtime variables --- src/content/docs/en/reference/configuration-reference.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/en/reference/configuration-reference.mdx b/src/content/docs/en/reference/configuration-reference.mdx index d16420e4a635a..30aeecc53b72e 100644 --- a/src/content/docs/en/reference/configuration-reference.mdx +++ b/src/content/docs/en/reference/configuration-reference.mdx @@ -1244,7 +1244,7 @@ export default defineConfig({ }) ``` -See [the sessions guide](/en/guides/sessions/) for more information. +See [the sessions guide](/en/guides/sessions/) for more information on [configuring session drivers with runtime variables](/en/guides/sessions/#configuring-sessions) and how to [interact with their data](/en/guides/sessions/#interacting-with-session-data). ### session.driver From a14b447b9b49c756ae55d16ab9677ade10401981 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 21 Apr 2026 19:18:22 +0200 Subject: [PATCH 4/6] format code snippet --- src/content/docs/en/guides/sessions.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/content/docs/en/guides/sessions.mdx b/src/content/docs/en/guides/sessions.mdx index fd3cec92c5c5d..3e0c0f7ff46e3 100644 --- a/src/content/docs/en/guides/sessions.mdx +++ b/src/content/docs/en/guides/sessions.mdx @@ -60,8 +60,8 @@ export default function (): SessionDriverConfig { You can then reference this file as the driver entrypoint in your Astro configuration: ```js title="astro.config.mjs" {7-9} -import { defineConfig, sessionDrivers } from 'astro/config' -import vercel from '@astrojs/vercel' +import { defineConfig, sessionDrivers } from "astro/config"; +import vercel from "@astrojs/vercel"; export default defineConfig({ adapter: vercel(), @@ -70,7 +70,7 @@ export default defineConfig({ entrypoint: new URL('./src/session-driver.ts', import.meta.url), } } -}) +}); ``` From ba350127ed9b280ba63aabcd40e052a143dc2b91 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 23 Apr 2026 14:26:11 +0200 Subject: [PATCH 5/6] small rewording --- src/content/docs/en/guides/sessions.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/en/guides/sessions.mdx b/src/content/docs/en/guides/sessions.mdx index 3e0c0f7ff46e3..b61c744f3ec08 100644 --- a/src/content/docs/en/guides/sessions.mdx +++ b/src/content/docs/en/guides/sessions.mdx @@ -42,7 +42,7 @@ export default defineConfig({ }) ``` -When you need to override options at runtime using environment variables, you can define the driver in a separate file and use the module as [entrypoint for the session driver](/en/reference/session-driver-reference/#entrypoint) in your configuration. +When you need to override options at runtime using environment variables, define the driver in a separate file and use the module as the [entrypoint for the session driver](/en/reference/session-driver-reference/#entrypoint). The following example configures the Redis driver with runtime variables in a file located in your `src` directory: @@ -57,7 +57,7 @@ export default function (): SessionDriverConfig { } ``` -You can then reference this file as the driver entrypoint in your Astro configuration: +You can then use this file as the driver entrypoint in your Astro configuration: ```js title="astro.config.mjs" {7-9} import { defineConfig, sessionDrivers } from "astro/config"; From 5c2b6582c42fa81f7913d2840e6d974a8d64bc8f Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 23 Apr 2026 15:31:09 +0200 Subject: [PATCH 6/6] maybe we also need a why --- src/content/docs/en/guides/sessions.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/en/guides/sessions.mdx b/src/content/docs/en/guides/sessions.mdx index b61c744f3ec08..8b026c193e5a3 100644 --- a/src/content/docs/en/guides/sessions.mdx +++ b/src/content/docs/en/guides/sessions.mdx @@ -42,7 +42,7 @@ export default defineConfig({ }) ``` -When you need to override options at runtime using environment variables, define the driver in a separate file and use the module as the [entrypoint for the session driver](/en/reference/session-driver-reference/#entrypoint). +You can also configure the session driver using environment variables. When defined in the configuration file, these variables are inlined at build time. If you need to override them at runtime, define the driver configuration in a separate file. Then use the module as the [driver's entrypoint](/en/reference/session-driver-reference/#entrypoint). The following example configures the Redis driver with runtime variables in a file located in your `src` directory: