Imagine an admin removes a contractor's admin role at the end of a project. The change is saved, the admin screen shows "Viewer," and everyone moves on. For the next hour, the contractor can still delete records, because the API checks the role inside their access token, and that token was issued before the change.
The opposite happens too. Someone is promoted to editor, but the edit buttons don't appear and the API keeps rejecting their requests until they log out and back in.
Both problems have the same cause. A JWT is a snapshot of who the user was when the token was issued. Changing the database doesn't change tokens that already exist.
Making permission changes take effect comes down to five decisions:
- Treat the claims in a token as a snapshot that can be stale, not as the source of truth.
- Decide which actions are allowed to trust that snapshot and which need a live check.
- Keep access tokens short-lived, revoke refresh tokens on a demotion, and consider a per-user permission version.
- Give the client a clear signal to refresh its token and retry.
- Don't forget long-lived connections, such as WebSockets, that never send a new token.
Why the token keeps the old role
A JWT carries its claims with it. RFC 7519, the JWT specification, doesn't define any way to revoke a token. Its jti claim is described as a way to prevent replay, not as a revocation feature. RFC 7009, which covers token revocation for OAuth, describes self-contained tokens as ones a resource server can validate without asking the authorization server. That's the benefit of JWTs and also the problem: if nobody asks, nobody finds out the role changed.
Identity providers say this plainly. Microsoft's guidance on group claims and app roles reminds developers that group information in a token is only current as of the moment the token was received. Firebase's custom claims documentation says new claims reach the client the next time a new ID token is issued.
How long "until it expires" really is
"It fixes itself when the token expires" sounds harmless until you look at the actual lifetimes. As of November 2026, the documented defaults are:
- Microsoft Entra ID: access tokens last between 60 and 90 minutes by default, averaging 75. With continuous access evaluation enabled, they can last up to 28 hours.
- Firebase Authentication: ID tokens last one hour, according to the session management documentation.
- Auth0: access tokens for a custom API default to 86,400 seconds, which is 24 hours, with a maximum of 30 days, per the access token lifetime documentation.
- NestJS: the official authentication documentation uses a 15-minute access token in its example, and notes that tokens already issued stay valid until they expire.
The OAuth 2.0 Security Best Current Practice (RFC 9700) recommends that access tokens have restricted privileges and short lifetimes, but it doesn't give a number. Whatever lifetime you choose is also the longest a removed permission can keep working, unless you add something else.
Revoking and granting are different problems
The two directions of a role change carry different risks:
- Removing a permission is a security problem. Until the change takes effect, someone can do something they're no longer allowed to do. For admin actions, money movement, data exports, or another tenant's data, even a few minutes may be too long.
- Granting a permission is a user experience problem. The user is blocked from something they're now allowed to do. It's frustrating, but nothing is exposed. A token refresh fixes it.
That difference should shape your design. You can tolerate some delay on grants, but you should be deliberate about how long a removal can linger.
Decide which actions can trust the token
You don't have to choose one strategy for the whole API. The OWASP Authorization Cheat Sheet recommends validating permissions on every request and denying by default. What changes between routes is where that validation gets its data.
A practical split:
- Low risk, reading the token is fine: showing navigation, reading your own profile, and viewing data the user could see under any role.
- Medium risk, a short delay is acceptable: routine edits within the user's own workspace. Short tokens or a permission version keep the delay bounded.
- High risk, check live data: user and role management, deleting or exporting data, payments and refunds, and anything that crosses a tenant boundary. Load the current permissions from the database, or from a short cache, on these routes.
Write the tiers down. When a new route is added, deciding which tier it belongs to is a quick, reviewable decision instead of an accident.
Option 1: short access tokens and refresh-token revocation
The simplest lever is lifetime. Short access tokens limit how long a stale role can last, and the refresh token becomes the point where the server can say no.
Two details are easy to miss:
- Revoking a refresh token doesn't cancel access tokens that are already issued. RFC 7009 says this directly in its implementation notes. Revocation stops the next refresh, not the current token. Firebase's session documentation points the same way. ID tokens are stateless and last an hour, and a server can only tell that a token was revoked by asking for its status. So after
revokeRefreshTokens(), a token that's already issued keeps passing a basic signature check until it expires, unless your server checks revocation. - Refresh tokens should rotate. RFC 9700 says refresh tokens for public clients, such as browser apps, must be sender-constrained or rotated. With rotation, reusing an old refresh token is treated as a sign of theft. Auth0's rotation documentation describes reuse detection that denies further requests until the user signs in again.
On a demotion, revoke the user's refresh tokens so they can't simply refresh into a new token with the old role. Then rely on one of the next two options to cover the time until the current access token expires.
Option 2: check live permissions on sensitive routes
For high-risk routes, look up the user's current permissions instead of reading them from the token. The token still proves who the user is, but the database decides what they can do.
NestJS makes it easy to slip into the opposite. The guards documentation shows a roles guard that assumes request.user already contains the user and their roles, which in a JWT setup usually means the roles came from the token. The newer NestJS authorization documentation, built around the @nestjs/authorization package introduced in 2026, loads the user by the token's subject on each request instead. Those packages were at version 0.1.x in November 2026, so check their status before adopting them; the pattern works with any guard.
A live check costs a database or cache read. A short cache keeps that cost low, but it reintroduces a smaller delay. RFC 7662, on token introspection, makes the same point about cached introspection results: caching creates a window in which a revoked token can still be used. Choose the cache lifetime as consciously as the token lifetime, and clear the cache entry when you change someone's permissions.
Option 3: a permission version stamp
A permission version gives you most of the benefit of live checks at a lower cost:
- Store a number, such as
perm_version, on each user record. - Increase it whenever that user's roles or permissions change.
- Include it as a claim when you issue a token.
- On requests, compare the token's version with the current one, from a cache or the database. If they differ, reject the request with a clear "token is stale" response.
This isn't a new idea. ASP.NET Core Identity uses a security stamp for the same purpose. Microsoft's Identity configuration documentation says the user's principal should be regenerated after security-sensitive events such as joining a role. The stamp's validation interval defaults to 30 minutes. The documentation notes that a long interval leads to stale claims, while a short one means more trips to the data store. Identity uses cookies rather than JWTs, but the trade-off is identical.
The version check costs one small lookup per request, which a cache handles well. It also catches grants: a promoted user gets a "stale" response, refreshes, and receives the new role right away.
Making the client catch up
Server-side checks decide what's allowed. The client still needs to know when to fetch a new token, or a promoted user keeps seeing the old interface.
A simple contract works well:
- The API returns a specific error when a token is stale, such as a 401 or 403 with a machine-readable code like
token_stale, rather than a generic "forbidden." - The client refreshes once and retries once. In Firebase,
getIdToken(true)orgetIdTokenResult(true)forces a new ID token with the latest custom claims, per the User reference. With your own refresh endpoint, call it, then repeat the original request. - If the retry fails too, treat it as a real denial. Show the right message instead of looping.
Microsoft's continuous access evaluation for apps follows a similar pattern with claims challenges: the API answers with a challenge, and the client obtains a new token and tries again.
Two client details matter:
- Make concurrent refreshes share one request. If several API calls fail at once and each triggers its own refresh, a rotated refresh token can be used twice, which reuse detection may treat as theft.
- Multiple tabs share the same session. Coordinate so one tab refreshes and the others pick up the result. How this works depends on your auth SDK, so test it with your setup.
Provider-specific notes
Each identity provider handles permission changes differently, so check the details for the one you use:
- Firebase: set roles with custom claims, then have the client force a refresh.
verifyIdTokenwithcheckRevokeddetects revoked sessions, but the Admin SDK reference describes it as an extra network request. Changing custom claims and revoking sessions are separate actions, so for a demotion, do both and test the result. - Microsoft Entra ID: group and app-role claims reflect the moment of issue. Continuous access evaluation reacts to critical events such as a disabled account, a password reset, or an admin revoking refresh tokens. Role and group changes aren't in that list, and the documentation says group membership changes can take up to a day to take effect under it. Revoking sign-in sessions through Microsoft Graph also comes with a short delay of a few minutes.
- Auth0: roles reach access tokens through its RBAC settings. Auth0's official docs don't spell out what happens after a role change, but an Auth0 staff answer on the community forum says the user needs to be re-authorized to get the new roles. With a 24-hour default lifetime, a live check or version check matters more here.
WebSockets: the connection that never asks again
A WebSocket connection is usually authenticated once, when it opens. After that, messages flow without a new token. The NestJS WebSocket guards documentation applies guards to message handlers, and a long-standing NestJS issue confirms that guards don't run on handleConnection.
So a user whose role was removed can keep an open socket with the old permissions for as long as the connection lasts:
- Check permissions on sensitive messages, the same way you would on sensitive HTTP routes, using live data or the permission version.
- Disconnect the user's sockets when their permissions change. Track sockets by user ID so a role change can close them. The client reconnects with a fresh token.
Testing it
Permission changes are easy to get wrong silently, because everything works for the person testing it. Add tests for the transitions, not just the steady state:
- Remove a role, then call a high-risk route with the old token. Expect a denial or a stale-token response.
- Grant a role, trigger the client's refresh flow, and confirm the new permission works without logging out.
- Revoke refresh tokens, then try to refresh. Expect a failure.
- Change a role while a WebSocket is open, then send a sensitive message.
- Fire several failing requests at once and confirm only one refresh happens.
Checklist
- Treat token claims as a snapshot, not the source of truth.
- Know your real token lifetime, from your provider's defaults or your own settings.
- Put every route in a risk tier, and check live permissions on the high-risk ones.
- On a demotion, revoke refresh tokens, and remember that issued access tokens stay valid until they expire.
- Add a permission version to tokens and compare it on requests, with a short cache that you clear on change.
- Return a specific stale-token error, refresh once, retry once.
- Share a single refresh across concurrent requests and tabs.
- Check sensitive WebSocket messages, and disconnect sockets when permissions change.
- Test the transitions: removal, grant, refresh revocation, sockets, and concurrent refreshes.



