Clear scheduler session cookie variants
This commit is contained in:
@@ -16,21 +16,36 @@ function clearCookie(response: NextResponse, name: string, domain?: string) {
|
||||
httpOnly: true,
|
||||
maxAge: 0,
|
||||
path: "/",
|
||||
sameSite: "lax",
|
||||
sameSite: "none",
|
||||
secure: true,
|
||||
});
|
||||
}
|
||||
|
||||
function getCookieDomains() {
|
||||
const configuredDomain = process.env.NEXTAUTH_COOKIE_DOMAIN || undefined;
|
||||
if (!configuredDomain) {
|
||||
return [undefined];
|
||||
}
|
||||
|
||||
return [undefined, configuredDomain, configuredDomain.replace(/^\./, "")];
|
||||
}
|
||||
|
||||
export function GET(request: NextRequest) {
|
||||
const response = NextResponse.redirect(new URL("/login", process.env.NEXTAUTH_URL || request.url));
|
||||
const configuredDomain = process.env.NEXTAUTH_COOKIE_DOMAIN || undefined;
|
||||
const domains = getCookieDomains();
|
||||
const requestSessionCookies = request.cookies
|
||||
.getAll()
|
||||
.map((cookie) => cookie.name)
|
||||
.filter((name) => name.includes("next-auth.session-token"));
|
||||
|
||||
for (const name of COOKIE_NAMES) {
|
||||
for (const suffix of CHUNK_SUFFIXES) {
|
||||
clearCookie(response, `${name}${suffix}`);
|
||||
if (configuredDomain) {
|
||||
clearCookie(response, `${name}${suffix}`, configuredDomain);
|
||||
}
|
||||
const sessionCookieNames = Array.from(new Set([
|
||||
...requestSessionCookies,
|
||||
...COOKIE_NAMES.flatMap((cookieName) => CHUNK_SUFFIXES.map((suffix) => `${cookieName}${suffix}`)),
|
||||
]));
|
||||
|
||||
for (const name of sessionCookieNames) {
|
||||
for (const domain of domains) {
|
||||
clearCookie(response, name, domain);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user