fix(auth): clear session in a plain route handler so logout sticks#398
Open
huv1k wants to merge 4 commits into
Open
fix(auth): clear session in a plain route handler so logout sticks#398huv1k wants to merge 4 commits into
huv1k wants to merge 4 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
347c060 to
602b595
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replace the
signOutAction()server-action logout with a dedicatedGET /api/auth/sign-outroute handler that the logout button hard-navigates to. Removes the now-unusedsignOutAction, simplifiescompleteOrySignOutto 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-Cookiedeletion reaches the browser. When sign-out runs inside anauth()-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.