mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-20 17:57:22 +02:00
🐛 Include locale when creating guest user
This commit is contained in:
parent
dc8de27682
commit
d1194400b2
2 changed files with 17 additions and 6 deletions
|
@ -23,23 +23,25 @@ export const middleware = withAuth(
|
|||
}
|
||||
|
||||
// Check if locale is specified in cookie
|
||||
const preferredLocale = req.nextauth.token?.locale;
|
||||
if (preferredLocale && supportedLocales.includes(preferredLocale)) {
|
||||
newUrl.pathname = `/${preferredLocale}${newUrl.pathname}`;
|
||||
let locale = req.nextauth.token?.locale;
|
||||
if (locale && supportedLocales.includes(locale)) {
|
||||
newUrl.pathname = `/${locale}${newUrl.pathname}`;
|
||||
} else {
|
||||
// Check if locale is specified in header
|
||||
const acceptLanguageHeader = headers.get("accept-language");
|
||||
const localeFromHeader = acceptLanguageHeader
|
||||
? languageParser.pick(supportedLocales, acceptLanguageHeader)
|
||||
: null;
|
||||
const locale = localeFromHeader ?? "en";
|
||||
locale = localeFromHeader ?? "en";
|
||||
|
||||
newUrl.pathname = `/${locale}${newUrl.pathname}`;
|
||||
}
|
||||
|
||||
const res = NextResponse.rewrite(newUrl);
|
||||
|
||||
await initGuest(req, res);
|
||||
await initGuest(req, res, {
|
||||
locale,
|
||||
});
|
||||
|
||||
return res;
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue