Set Firebase Auth custom claims and force client token refresh

domain: firebase.google.com · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Using the Firebase Admin SDK on your server, call admin.auth().setCustomUserClaims(uid, claimsObject) to write custom claims to the user record; this does not immediately update tokens already in circulation.
  2. New claims are only reflected in the ID token after the next token refresh; to signal the client to refresh immediately, write the current server timestamp to a known path in Realtime Database or Firestore for that user.
  3. On the client, listen to the database path; when a new timestamp appears that is newer than the token's issued-at time, call user.getIdToken(true) to force a token refresh.
  4. After the forced refresh, use the new ID token for API calls; the custom claims will now be present in the decoded token payload.
  5. To revoke all refresh tokens for a user (full session invalidation), call admin.auth().revokeRefreshTokens(uid); clients must re-authenticate after revocation.
  6. Validate custom claims on your backend by verifying the ID token with the Admin SDK or by checking claims in a JWT verified against Firebase's JWKS endpoint.

Known gotchas

Related routes

Add custom claims at login with Auth0 Actions (post-login trigger)
auth0.com · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans