Files
petvity/lib/auth/session-cookie.test.ts
T
CatoandClaude f0d9e01cb3 ci(browser-smoke): account journey in Chromium, and sign-out that sticks (#144)
* fix(auth): the proxy no longer re-issues the session cookie

Auth.js's auth() proxy wrapper appends a fresh session cookie to every
response it handles, Link prefetches included. A prefetch that left the
browser before Sign out came back after it and set the old, still-valid
JWT again, so the person stayed signed in. The new browser journey hit
this in about one sign-out in three.

The proxy now drops only the session-token Set-Cookie it would add; the
session still rolls through /api/auth/*, which SessionProvider calls on
every page load.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

* ci(browser-smoke): register, sign out, sign in and no stray Google button

browser-smoke.yml runs scripts/ci/account-journey.mjs in Chromium against
the production build and a throwaway Postgres 17: register through
/register, see the portal, sign out from the sidebar, a wrong password
refused, the right one accepted, no sideways scroll on /login and
/register at 390px. With no GOOGLE_* pair it checks that no Google
provider is mounted and no Google button is drawn, the guard for the
invalid_client sign-in of 2026-10-30.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-30 11:13:15 +01:00

35 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { withoutSessionCookie } from "./session-cookie";
function response(...cookies: string[]) {
const res = new Response(null);
for (const c of cookies) res.headers.append("set-cookie", c);
return res;
}
describe("withoutSessionCookie", () => {
it("drops a re-issued session token, plain or __Secure-, whole or chunked", () => {
const res = withoutSessionCookie(
response(
"authjs.session-token=abc; Path=/; HttpOnly",
"__Secure-authjs.session-token=abc; Path=/; Secure",
"authjs.session-token.0=abc; Path=/",
),
);
expect(res.headers.getSetCookie()).toEqual([]);
});
it("keeps every other cookie, such as the locale", () => {
const res = withoutSessionCookie(
response("NEXT_LOCALE=de; Path=/", "authjs.session-token=abc; Path=/"),
);
expect(res.headers.getSetCookie()).toEqual(["NEXT_LOCALE=de; Path=/"]);
});
it("leaves a response without a session cookie untouched", () => {
const res = response("authjs.csrf-token=x; Path=/");
expect(withoutSessionCookie(res)).toBe(res);
expect(res.headers.getSetCookie()).toEqual(["authjs.csrf-token=x; Path=/"]);
});
});