From ddd5ae5ec50747ad563bb1c9f4cbf1ab258b4271 Mon Sep 17 00:00:00 2001 From: Jan Amann Date: Mon, 23 Dec 2024 09:40:01 +0100 Subject: [PATCH] fix: Make locale cookie a session cookie (#1634) Initially, I planned to add an expiration of 5 hours to the locale cookie for `next-intl@4` to comply with GDPR regulations. However, this has the implication that if the browser remains open for longer than 5 hours, the cookie can be reset in the middle of a session. Due to this, it seems more reasonable to not set an expiration at all, turning the cookie into a session cookie. Session cookies expiry only when a browser is closed. On mobile, this can be even more beneficial, as browsers are rarely closed (the browser can clear cookies though if memory is constrained). --- docs/src/pages/docs/routing.mdx | 7 +++---- examples/example-app-router/tests/main.spec.ts | 2 -- .../navigation/react-client/createNavigation.test.tsx | 11 +++-------- packages/next-intl/src/routing/config.tsx | 3 +-- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/docs/src/pages/docs/routing.mdx b/docs/src/pages/docs/routing.mdx index acf996ce8..376d15816 100644 --- a/docs/src/pages/docs/routing.mdx +++ b/docs/src/pages/docs/routing.mdx @@ -473,11 +473,10 @@ In this case, only the locale prefix and a potentially [matching domain](#domain ### Locale cookie [#locale-cookie] -If a user changes the locale to a value that doesn't match the `accept-language` header, `next-intl` will set a cookie called `NEXT_LOCALE` that contains the most recently detected locale. This is used to [remember the user's locale](/docs/routing/middleware#locale-detection) preference for future requests. +If a user changes the locale to a value that doesn't match the `accept-language` header, `next-intl` will set a session cookie called `NEXT_LOCALE` that contains the most recently detected locale. This is used to [remember the user's locale](/docs/routing/middleware#locale-detection) preference for subsequent requests. By default, the cookie will be configured with the following attributes: -1. [**`maxAge`**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#max-agenumber): This value is set to 5 hours in order to be [GDPR-compliant](#locale-cookie-gdpr) out of the box. 2. [**`sameSite`**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value): This value is set to `lax` so that the cookie can be set when coming from an external site. 3. [**`path`**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#pathpath-value): This value is not set by default, but will use the value of your [`basePath`](#base-path) if configured. @@ -514,9 +513,9 @@ export const routing = defineRouting({