fix(portal): skip admin Bearer JWT on customer-portal routes - #3
Merged
Conversation
The customer portal authenticates via the customer-portal-token header, not the admin Bearer JWT. But authLink was attaching the Bearer JWT to every request if one existed in localStorage — including portal requests. For users who have ever logged into Lago admin in the same browser, the admin JWT (12h TTL) sits in localStorage. Once it expires, every customer-portal GraphQL request returns expired_jwt_token (because GraphqlController validates the Bearer JWT before resolving), even though the customer-portal session itself is fresh and valid. This broke the recently-shipped stale-tab-recovery flow into an infinite loop: portal hits expired_jwt → bounces to host app → host mints fresh portal URL → portal still has expired admin JWT in localStorage → expired_jwt → bounces again. Fix: only attach the Bearer header when NOT on a /customer-portal/* route. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Root cause
authLink in src/core/apolloClient/init.ts attaches Authorization: Bearer to every GraphQL request if there's an authToken in localStorage. This includes /customer-portal/* requests, which shouldn't be authenticating via the admin JWT at all (they use the customer-portal-token header).
If a user has ever logged into Lago admin in the same browser, the admin JWT (12h TTL) sits in localStorage forever. Once it expires, every customer-portal GraphQL request fails with expired_jwt_token — because GraphqlController validates the Bearer JWT before resolving the operation — even though the customer-portal session itself is fresh.
This was hidden until we wired the stale-tab recovery flow (PR #2). Now it manifests as an infinite loop: portal hits expired_jwt → bounces back to host app → host mints fresh portal URL → new portal page still sends the expired admin JWT from localStorage → expired_jwt → bounces again.
Fix
Only send Authorization: Bearer header when NOT on a /customer-portal/* route. The customer-portal-token header is still sent on portal routes; the admin Bearer is sent everywhere else as before.
Test plan