[Fix] Token Store Overrides are now Respected #1156
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds request-like tokenStore authentication tests and a per-call Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ClientApp as ClientApp/_getSession
participant CookieHelper as _createCookieHelper
participant TokenStore
participant Server as serverApp.getUser
Client->>ClientApp: request session (maybe with request-like tokenStore)
ClientApp->>CookieHelper: create cookie helper (pass overrideTokenStoreInit?)
CookieHelper->>TokenStore: initialize using override or instance default
ClientApp->>Server: serverApp.getUser (uses request-like tokenStore / cookies)
Server->>TokenStore: read tokens from provided tokenStore/cookies
Server-->>ClientApp: user payload
ClientApp-->>Client: session/user response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
Greptile OverviewGreptile SummaryThis PR fixes a subtle override ordering bug in the Stack client app implementation: It also adds e2e coverage for Main concern is around the new cookie-based test: it appears to construct Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
autonumber
participant Caller as App caller
participant App as _StackClientAppImplIncomplete
participant CookieHelper as CookieHelper factory
participant TokenStore as _getOrCreateTokenStore
participant Session as InternalSession
Caller->>App: getUser({ tokenStore: override })
Note over App: overrideTokenStoreInit derived from override
App->>CookieHelper: _createCookieHelper(overrideTokenStoreInit)
CookieHelper-->>App: CookieHelper (real vs placeholder)
App->>TokenStore: _getOrCreateTokenStore(cookieHelper, overrideTokenStoreInit)
TokenStore-->>App: Store<TokenObject>
App->>Session: _getSessionFromTokenStore(store)
Session-->>App: InternalSession
App-->>Caller: user (resolved via override token store)
Note over App,CookieHelper: PR change: overrideTokenStoreInit now influences _createCookieHelper
|
There was a problem hiding this comment.
Pull request overview
Fixes getUser() so tokenStore overrides (especially request-like objects) are respected during session initialization, avoiding premature Next.js RSC headers()/cookies() access (e.g., Bun middleware context).
Changes:
- Thread
overrideTokenStoreInitthrough_getSession()→_createCookieHelper()so cookie helpers aren’t created when the override doesn’t require cookies. - Add E2E coverage for request-like
tokenStoreoverrides (cookie header +x-stack-auth) and verify overrides don’t mutate the default store. - Minor formatting cleanup in the shared client interface.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts | Uses the override tokenStore init to decide whether to create a real cookie helper, preventing RSC header access when an override is provided. |
| packages/stack-shared/src/interface/client-interface.ts | Removes an extra blank line (no functional impact). |
| apps/e2e/tests/js/auth-like.test.ts | Adds E2E tests validating request-like tokenStore overrides are honored and don’t overwrite default token store state. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
51e60c1 to
165f3f5
Compare
165f3f5 to
0d80aac
Compare
Context
Recently, a user raised this issue, which indicated that
tokenOverrideswere not being respected/used in thegetUser()function. If we trace the flow through this function, we seethis._getSession -> this._getOrCreateTokenStore -> _createCookieHelper -> createCookieHelper -> createNextCookieHelper -> await rscHeaders(). What this means is that even when arequestLike tokenOverridewas passed, we would not end up using it because thecreateCookieHelpercall occurs before the extant override checking logic ingetOrCreateTokenStore, and thecreateCookieHelperdidn't check the override but only the defaulttokenStoreInit. This caused the error to propagate up.Summary of Changes
We check the
tokenStoreOverridein thecreateCookieHelperfunction now, preventing this issue from happening. We also add extra test coverage to verify that overrides are respected, and don't overwrite the default token store.Out of Scope Discussion
The original issue was raised with a
bunruntime runningnext.jscode. There seems to be some incompatibility betweenbun 1.3.8andnextjs 15+, not just with our backend but with fetching and working with responses from anynextjsserver.Summary by CodeRabbit
Tests
Refactor