Clear scheduler session cookie variants
Create PR containing updated CHANGELOG.md and release packages to NPM once PR is merged / Release (push) Has been cancelled
Run i18n AI automation / Run i18n (push) Has been cancelled
Next.js Bundle Analysis / analyze (push) Has been cancelled

This commit is contained in:
Zachariah K. Sharma
2026-06-15 11:25:52 -06:00
parent 635935c3ba
commit efb5155daf
@@ -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);
}
}