fix(next-auth): detect Node responses by a callable headers.append - #13486
Open
endlessdev wants to merge 1 commit into
Open
fix(next-auth): detect Node responses by a callable headers.append#13486endlessdev wants to merge 1 commit into
endlessdev wants to merge 1 commit into
Conversation
`"headers" in response` is used to tell a Web `Response` from a Node
`ServerResponse` before appending `set-cookie`. Node's `ServerResponse` has no
`headers` property, so the check works there — but it is not portable.
Bun's `node:http` `ServerResponse` *does* expose `headers`, and it is a plain
object rather than a `Headers` instance. The check therefore takes the Web
branch and throws:
TypeError: response.headers.append is not a function
Every session-reading Pages Router API route (`auth(req, res)`,
`getServerSideProps`) returns a 500 as a result. The process still boots and
health checks still pass, so this fails silently in production.
Require a callable `append` instead. Real `Response` objects keep the `Headers`
path; every `ServerResponse` falls through to `appendHeader`, which Node and Bun
both implement.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
@endlessdev is attempting to deploy a commit to the authjs Team on Vercel. A member of the Team first needs to authorize it. |
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.
☕️ Reasoning
initAuthdecides how to attachset-cookieby duck-typing the response object:Node's
http.ServerResponsehas noheadersproperty, so on Node this correctlyfalls through to
appendHeader. But the check is not portable: Bun'snode:httpServerResponsedoes exposeheaders, and it is a plain object rather than aHeadersinstance. The check takes the Web branch and throws:Thirty-second reproduction, no next-auth involved:
So on Bun the discriminator says "Web Response", the Web branch is taken, and
headers.appendisundefined.Impact
Every Pages Router route that reads the session via
auth(req, res)(alsogetServerSideProps) returns 500 on Bun. In our app that was 19 routes,including wallet, subscription, and certification endpoints.
What makes this nasty is that nothing fails loudly: the app boots, health
checks pass, and a rolling deploy completes green. We only found it by probing
the routes directly and comparing status codes against Node:
/api/v1/wallet/card/api/v1/subscription/list/api/v1/short-term/listPOST /api/v1/slackFix
Require a callable
appendbefore taking the Web branch:Responseobjects (App Router) still take theHeaderspath — unchanged.ServerResponsefalls through toappendHeader, which Node (≥18.3) andBun both implement.
The two duplicated call sites are folded into one
appendSetCookiehelper so thereasoning lives next to the check.
Verified against
next-auth@5.0.0-beta.32in production: with this change Bunreturns exactly the same status codes as Node on all of the routes above, and the
TypeErrordisappears from the logs.🧢 Checklist
I did not add a unit test: exercising this line requires
getSessionto return aresponse that actually carries
set-cookie, which needs more mocking than theexisting suite sets up. Happy to add one if you'd like it — just say which shape
you'd prefer (mocking
getSession, or an e2e run under Bun).🎫 Affected issues
I could not find an existing issue for this.
📌 Resources
ServerResponsehas noheaders: https://nodejs.org/api/http.html#class-httpserverresponseresponse.appendHeader(Node ≥18.3): https://nodejs.org/api/http.html#responseappendheadername-value