Skip to content

Sign this browser out even when the auth server fails - #39

Merged
Githinj merged 2 commits into
mainfrom
fix/sign-out-local-fallback
Nov 16, 2026
Merged

Githinj merged 2 commits into
mainfrom
fix/sign-out-local-fallback

Conversation

@Githinj

@Githinj Githinj commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Part of SEC-240.

Merge this before or together with #34. The bug isn't live on main today. It appears when #34 brings in supabase-js 2.119.

Why

supabase-js 2.119 fixed global sign-out (supabase/supabase-js#2786). If the auth server can't be reached or returns an error, signOut() now keeps the local session and returns the error. Before, it cleared the session anyway.

Our signOut action ignored the error and redirected to /login. With 2.119, a failed server call would leave the admin on /login still signed in. The same action backs the sign-out buttons on /admin and /no-access, and on #16's branch also /portal and /portal/mfa.

Change

src/app/(app)/admin/actions.ts:

  • signOut() checks the returned error and also catches a throw.
  • On failure it logs the message (as failed() does for other actions), then calls signOut({ scope: "local" }), which supabase-js's own migration note recommends.
    • Local sign-out clears this browser's session cookies before (2.119) or regardless of (2.118) the server call, so it works with the server down.
    • The refresh token then stays valid on the server until it expires. That's the best possible without the server.
  • If the local call throws too, the error is logged and the redirect still happens. redirect("/login") stays outside every try/catch, because it works by throwing.
  • The happy path is unchanged: one global sign-out, then /login.
  • The change stays inside signOut(), including its comment. Phase 1C: client portal #16 and Record which video platform serves each site (SEC-264) #25 add inviteClientUser directly above it. With the change kept inside, both branches test-merge with this one without conflicts (git merge-tree).

Tests

tests/sign-out.test.ts stubs createSessionClient. It also makes redirect throw, as Next.js does. It covers five cases:

Auth server Expected
accepts one global sign-out, then /login, nothing logged
unreachable (AuthRetryableFetchError) local sign-out runs before the redirect
500 (AuthApiError) same
request throws same
local fallback fails too still redirects to /login

Three of the five fail against the old action.

Run locally: white-label check, typecheck, lint, and vitest run (95 passed). No build or browser tests were run locally; CI runs both. No browser test presses Sign out today (e2e-admin/ has no sign-out step), so the real-stack path is covered only by these unit tests.

🤖 Generated with Claude Code

supabase-js 2.119 (in Dependabot's #34) changes a global signOut():
when the auth server can't be reached or returns an error, it now
keeps the local session and returns the error. Our signOut action
ignored that error and redirected to /login, so an admin would land
there still signed in.

The action now checks the error, and also catches a throw. On failure
it logs the message and falls back to signOut({ scope: "local" }),
which clears this browser's session cookies without needing the
server, then redirects. The redirect stays outside every try/catch.
The happy path is unchanged: one global sign-out, then /login.

tests/sign-out.test.ts stubs the session client and covers the
server accepting, being unreachable (AuthRetryableFetchError),
returning a 500 (AuthApiError), throwing, and the local fallback
failing too. Three of the five fail against the old action.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
vx44-platform Ready Ready Preview Nov 16, 2026 4:36pm UTC

The portal branch (#16) and #25 add inviteClientUser directly above
signOut, so a helper and comment there conflicted with them. The comment
and the message() helper now sit inside signOut, and both branches
test-merge cleanly with this one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Githinj
Githinj merged commit 4df7edd into main Nov 16, 2026
4 checks passed
Githinj added a commit that referenced this pull request Nov 16, 2026
Brings Next.js 16.4.6 and React 19.3.1 (#26), the sign-out fallback (#39), the dependency and CI updates (#30-#34, #38) and the docs since bda697c. No conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Githinj added a commit that referenced this pull request Nov 17, 2026
…41)

e2e-admin/sign-out.spec.ts signs out from both places main offers it:
the back-office header (an admin after MFA) and the no-access page (an
account without the admin role). After each, the browser is on /login,
no sb-*-auth-token cookie is left, and /admin sends the visitor back to
/login. Own accounts, so it doesn't depend on the other signed-in tests.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant