Repository navigation
Conversation
Logout cleared only one of the three better-auth cookies, so a session survived logout. The handler copied set-cookie values from a Headers object onto the Hono context through a hand-rolled forwardCookies helper, and Hono's c.header replaces rather than appends. Ask better-auth for the signOut response itself with asResponse: true and append its set-cookie values to the redirect Response. No code in this repo then decides how cookies are forwarded, so a future handler cannot lose headers the same way, and no cookie name appears locally. asResponse makes better-auth return APIErrors as error responses instead of throwing them (dispatch.mjs:193,249,258), so the status is now checked. Without that check a failed sign-out redirected to /?message=Bye! while the session still stood. forwardCookies and src/app/utils/cookies.js are gone; AGENTS.md lists the remaining utilities.
Pin the security attributes of the session cookie set by magicLinkVerify, and that the authorize endpoint sets no cookie. The magic-link header handling was duplicated between getAuthHeaders and the new test, including the workaround for Better Auth returning either a Headers object or an array of pairs. One exported helper now carries it for both.
mroderick
force-pushed
the
fix/logout-set-cookie
branch
from
November 12, 2026 08:18
5e8f04f to
e7dd33d
Compare
mroderick
marked this pull request as ready for review
November 12, 2026 09:14
olleolleolle
approved these changes
Nov 12, 2026
olleolleolle
left a comment
Collaborator
There was a problem hiding this comment.
Good test descriptions!
This branch has not been deployed
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.
Logout was clearing only one of the three better-auth cookies, so a session survived logout. This branch carries the fix that #103 and #107 built between them and never reached main, plus the GET-verb coverage salvaged from #104.
Hono's
c.header("Set-Cookie", ...)replaces rather than appends, which is how the hand-rolledforwardCookieshelper lost the second and third clearing cookie. The handler now asks better-auth for thesignOutresponse itself withasResponse: trueand appends itsset-cookievalues to the redirectResponse.forwardCookiesandsrc/app/utils/cookies.jsare gone,AGENTS.mdno longer lists a cookies utility, and no cookie name appears in the handler: what gets cleared is whateversignOutreturns.Review notes
Look at the error path first. It is the only behaviour change.
asResponse: truemakes better-auth returnAPIErrors as error responses instead of throwing them (node_modules/better-auth/dist/api/dispatch.mjs:193,249,258). Without a status check, a failed sign-out would redirect to/?message=Bye!while the session still stood. The handler returns the failure and logs the status instead, and a test injects asignOutthat answers 500.Two things this branch deliberately does not change:
/logoutkeeps its GET verb, whichsrc/app/routes/auth.jsalready registers before this diff. The added GET test pins existing behaviour; whether session clearing should answer GET at all is a separate decision.APIErrorfailure fromsignOutstill escapes to Hono's default 500. The previous handler threw in the same case, and what a failed logout should answer is not decided anywhere in the app.Also deliberately not done: no better-auth helper wraps this direction.
applySetCookiesandsetCookieToHeaderboth write a requestcookieheader (applySetCookiesends intarget.set("cookie", ...)), so the append happens on theResponsedirectly.One test-helper change rides along: the magic-link header handling moved into a single exported helper in
test/helpers/test-instance.js. The new cookie-attribute test needs the raw response headers, the existing helper only returned the cookie, and copying its Better Auth header-shape workaround would have left two copies to drift.Logout answers with these three headers
The integration tests cover magic-link session cookie attributes, authorize setting no cookie, POST and GET
/logoutclearing all three cookies with their attributes, and a failed sign-out propagating its status.Supersedes #103 (closed) and #107 (merged into #103's branch, not main); closes #104, whose other two tests targeted code this branch deletes.