Chunk the Next.js session cookie to avoid the 4KB browser limit - #80
Merged
Merged
Conversation
|
Important Review available on request
Reviews should be triggered manually for repositories with fewer than 10 stars. Select Trigger review above or comment ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
janithjay
force-pushed
the
fix-nextjs-cookie-chunking
branch
4 times, most recently
from
August 17, 2026 05:50
5830ecf to
01ae151
Compare
…KB browser limits in Nextjs Signed-off-by: janithjay <janithjayashan018@gmail.com>
janithjay
force-pushed
the
fix-nextjs-cookie-chunking
branch
from
August 17, 2026 05:51
01ae151 to
356a93a
Compare
brionmario
approved these changes
Aug 17, 2026
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.
Purpose
@thunderid/nextjsbuilds its session cookie the same way the Nuxt SDK used to:SessionManager.createSessionTokenembeds the full access token, ID token, and refresh token inside the session cookie's own JWT payload. That routinely exceeds the browser's hard ~4096-byte per-cookie limit, and browsers silently drop any Set-Cookie over that limit. So a user can complete the OAuth exchange successfully and still end up signed out. This is the same root cause fixed for Nuxt in PR #74, just not yet ported to nextjs.Approach
Reuses the
CookieChunkingutility added to@thunderid/nodein PR #74 (chunk name/size math only - no cookie I/O of its own). Adds a thinpackages/nextjs/src/utils/chunkedCookie.tsadapter (getChunkedCookie/setChunkedCookie/deleteChunkedCookie) over it, then wires that into every place@thunderid/nextjstouches the session cookie,getAccessToken,getSessionPayload,getSessionId.signInAction,handleOAuthCallbackAction,refreshToken,signOutAction,clearSession.sessionUtils.ts(shared helpers used by the middleware).thunderIDProxy.tsmiddleware - reads viaNextRequest.cookies, writes viaNextResponse.cookies, and rewrites the rawCookierequest header it forwards downstream so the same-request Server Component render sees the fresh, possibly-chunked session immediately.The temp session cookie is untouched, it's always small and never needs chunking.
Related Issues
Related PRs
mainuntil Chunk the Nuxt session cookie instead of trimming its payload #74 merges )Checklist
breaking changelabel added.Security checks