persist locale on language switch when functional consent given

This commit is contained in:
2026-08-13 00:57:02 +02:00
parent 5f76050fa8
commit 720bf6914b
4 changed files with 67 additions and 31 deletions
+8 -4
View File
@@ -32,6 +32,10 @@ export type LocaleMiddlewareResult = {
location: string;
type: 'redirect';
} | {
cookie?: {
name: string;
value: string;
};
type: 'next';
};
type CreateLocaleMiddlewareArgs = {
@@ -68,10 +72,10 @@ type CreateLocaleMiddlewareArgs = {
* import { localeMiddleware } from './ipal.middleware' // created from this factory
* export function proxy(req) {
* const r = localeMiddleware(req)
* if (r.type === 'next') return NextResponse.next()
* const res = NextResponse.redirect(r.location)
* // cookie is optional: only present when the visitor consented to the
* // gating category (functional by default). Guard before setting.
* // Both results may carry an optional cookie — 'next' when the visitor
* // switched language (URL locale differs from the stored one) and consented,
* // 'redirect' on the initial locale negotiation. Set it whenever present.
* const res = r.type === 'next' ? NextResponse.next() : NextResponse.redirect(r.location)
* if (r.cookie) res.cookies.set(r.cookie.name, r.cookie.value)
* return res
* }