Custom JWT claims
Add `subscriptionTier`, `appUserId`, or feature flags to the access token.
Two hooks: customizeSessionData (server-side state, available on refresh) and customizeTokenPayload (what's in the JWT itself).
Read on the client
In React, the same value lands on useUser() if you also surface it via getSessionUserData:
Don't do
- Don't put 50 permissions in the JWT — it bloats every request. Keep them on the session row, query server-side.
- Don't put PII (emails are fine; SSNs aren't). The JWT is signed, not encrypted — anyone with the token can read it.
- Don't put data that changes often (e.g.
lastSeenAt). It'll be stale on the very next request.
Re-issuing on tier change
When the user upgrades from free to pro, you want them to see the new tier without re-logging in. Two options:
- Wait for refresh. On the next refresh (within
accessTokenValidity),customizeTokenPayloadre-runs with the fresh data. - Force a refresh. Server-side, revoke the session and trigger a re-login. Or trigger
client.refresh()from the frontend after the upgrade succeeds.
For a 15-minute access token validity, waiting is usually fine. For a 24-hour validity, force the refresh.