mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-20 01:37:23 +02:00
🐛 Fix session empty session when logging out (#1345)
This commit is contained in:
parent
b75dfed611
commit
8f34f755b9
5 changed files with 36 additions and 36 deletions
|
@ -1,16 +1,15 @@
|
|||
import languages from "@rallly/languages";
|
||||
import languageParser from "accept-language-parser";
|
||||
import { NextResponse } from "next/server";
|
||||
import withAuth from "next-auth/middleware";
|
||||
|
||||
import { initGuest } from "@/app/guest";
|
||||
import { getLocaleFromHeader, initGuest } from "@/app/guest";
|
||||
import { isSelfHosted } from "@/utils/constants";
|
||||
|
||||
const supportedLocales = Object.keys(languages);
|
||||
|
||||
export const middleware = withAuth(
|
||||
async function middleware(req) {
|
||||
const { headers, nextUrl } = req;
|
||||
const { nextUrl } = req;
|
||||
const newUrl = nextUrl.clone();
|
||||
|
||||
// if the user is already logged in, don't let them access the login page
|
||||
|
@ -28,20 +27,14 @@ export const middleware = withAuth(
|
|||
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;
|
||||
locale = localeFromHeader ?? "en";
|
||||
locale = await getLocaleFromHeader(req);
|
||||
|
||||
newUrl.pathname = `/${locale}${newUrl.pathname}`;
|
||||
}
|
||||
|
||||
const res = NextResponse.rewrite(newUrl);
|
||||
|
||||
await initGuest(req, res, {
|
||||
locale,
|
||||
});
|
||||
await initGuest(req, res);
|
||||
|
||||
return res;
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue