persist locale on language switch when functional consent given
This commit is contained in:
+8
-4
@@ -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
|
||||
* }
|
||||
|
||||
Reference in New Issue
Block a user