mirror of
https://github.com/bitbaum/petvity.git
synced 2026-12-04 15:47:01 +01:00
* 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>
23 lines
1.0 KiB
TypeScript
23 lines
1.0 KiB
TypeScript
/**
|
|
* The proxy reads the session; it must never write it.
|
|
*
|
|
* Auth.js's `auth()` proxy wrapper re-issues the session cookie on every
|
|
* request it sees, Link prefetches included. With JWT sessions a prefetch
|
|
* that left the browser before "Sign out" comes back after it and sets the
|
|
* old, still-valid token again — the person is signed straight back in. The
|
|
* browser journey (scripts/ci/account-journey.mjs) caught this in about one
|
|
* sign-out in three. The session keeps rolling where it should: /api/auth/*,
|
|
* which SessionProvider calls on every page load.
|
|
*/
|
|
const SESSION_COOKIE = /^(__Secure-)?authjs\.session-token(\.\d+)?=/;
|
|
|
|
export function withoutSessionCookie<R extends Response>(response: R): R {
|
|
const cookies = response.headers.getSetCookie();
|
|
if (!cookies.some((c) => SESSION_COOKIE.test(c))) return response;
|
|
response.headers.delete("set-cookie");
|
|
for (const cookie of cookies) {
|
|
if (!SESSION_COOKIE.test(cookie)) response.headers.append("set-cookie", cookie);
|
|
}
|
|
return response;
|
|
}
|