Skip to content

fix(auth): clear session in a plain route handler so logout sticks#398

Open
huv1k wants to merge 4 commits into
mainfrom
huv1k/logout-session-not-cleared
Open

fix(auth): clear session in a plain route handler so logout sticks#398
huv1k wants to merge 4 commits into
mainfrom
huv1k/logout-session-not-cleared

Conversation

@huv1k

@huv1k huv1k commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

What

Replace the signOutAction() server-action logout with a dedicated GET /api/auth/sign-out route handler that the logout button hard-navigates to. Removes the now-unused signOutAction, simplifies completeOrySignOut to skip the Ory RP-initiated logout round-trip, and keeps the PostHog identity reset on logout.

Why

The dashboard session is a self-contained JWT cookie, so logout only takes effect if that cookie's Set-Cookie deletion reaches the browser. When sign-out runs inside an auth()-wrapped request, the Auth.js wrapper re-issues a refreshed session cookie at the end of the request, clobbering the deletion and leaving the user logged in. A plain, unwrapped route handler makes the deletion the final word. The hard navigation also keeps the "Logging out…" overlay up until the page unloads (no soft RSC redirect flash), and the Ory path now redirects straight to the post-logout page, relying on the existing Kratos + Hydra admin revocations. Integration tests exercise the new route.

Note

The root cause is environment-agnostic, so this fixes logout on preview deployments as well as production — clearing the cookie in an unwrapped route handler makes the deletion stick regardless of VERCEL_ENV.

@cla-bot cla-bot Bot added the cla-signed label Jun 11, 2026
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
web Ready Ready Preview, Comment Jun 12, 2026 11:38am

Request Review

Sign-out ran inside the auth.signOut tRPC mutation, whose route is wrapped
by the Auth.js auth() helper. With the JWT session strategy that wrapper
re-issues a refreshed session cookie at the end of the request, clobbering
the Set-Cookie deletion that signOut() emits — so the authjs.session-token
survived and /dashboard stayed authenticated after logout.

Move sign-out to a dedicated GET /api/auth/sign-out route (not auth()-wrapped),
hard-navigated to by the logout button, so the cookie deletion is the final
word and the overlay stays up until unload. Skip the Ory RP-initiated logout
round-trip and redirect straight to the post-logout page, relying on the
existing Kratos + Hydra admin revocations. Remove the broken tRPC signOut
procedure.
Resolve logout conflicts: keep the dedicated GET /api/auth/sign-out route
(no overlay flash, single redirect) over main's reverted-to server action,
while integrating main's PostHog identity reset on logout. Remove the now-dead
signOutAction and its tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant