Verify JWTs locally with a JWKS instead of calling the auth server on every request
Calling the auth server to check every access token costs a network round-trip per request. With asymmetric signing keys, a server can verify the signature itself against a cached JWKS. Tested in Node.js with WebCrypto: one JWKS fetch for 1,000 requests and about 60 µs per check, plus the trade-off: a signed-out token keeps working until it expires.
If your API checks each request’s access token by calling the auth server (in Supabase, auth.getUser(token)), every request pays a network round-trip, and the auth server sees one call per request. With asymmetric signing keys (ES256 or RS256), you don’t need to ask: fetch the issuer’s public keys once from its JWKS endpoint, cache them, and verify the signature locally, then check iss and exp yourself. In my test with Node’s WebCrypto, 1,000 requests needed one JWKS fetch and each verification took about 60 µs. The trade-off is real and worth stating plainly: the server no longer learns that a user signed out, so a signed-out token keeps working until its exp, an hour by default in Supabase. In supabase-js, auth.getClaims(token) does this for you, and falls back to a server call when the project still uses a symmetric secret.

Local verification removes a network hop per request and moves revocation from the auth server to the token’s expiry.
Why did this matter in a real app?
The CRM I built for a sales team polls for notifications every 45 seconds in each open tab. Each poll made four Supabase requests: one to Auth to check the token, one for the user’s profile, one for the list and one for the unread count. That poll was nearly all of the app’s traffic: about 305 gateway requests and 70 Auth requests an hour. Switching the token check to local verification removes the Auth call from every poll, which should cut Supabase requests by about a quarter. The profile lookup stays, so a deactivated account or a role change still takes effect on the next request.
How does local verification work?
A JWKS (JSON Web Key Set) is a list of the issuer’s public keys, each with a kid. The token’s header names the kid it was signed with. Verifying is four steps: pick the key by kid, check the signature with an algorithm you chose, then check the issuer and expiry.
const { subtle } = globalThis.crypto; const json = (s) => JSON.parse(Buffer.from(s, "base64url").toString()); export function localVerifier(fetchJwks, { issuer, now = () => Date.now() } = {}) { let keys; // fetched once; refetch on an unknown kid to follow key rotation return async (token) => { keys ??= new Map( await Promise.all( (await fetchJwks()).keys.map(async (k) => [ k.kid, await subtle.importKey("jwk", k, { name: "ECDSA", namedCurve: "P-256" }, false, ["verify"]), ]) ) ); const [h, b, s] = token.split("."); const head = json(h); if (head.alg !== "ES256") throw new Error("unexpected alg"); const key = keys.get(head.kid); if (!key) throw new Error("unknown key"); const ok = await subtle.verify({ name: "ECDSA", hash: "SHA-256" }, key, Buffer.from(s, "base64url"), Buffer.from(`${h}.${b}`)); if (!ok) throw new Error("bad signature"); const claims = json(b); if (claims.iss !== issuer) throw new Error("wrong issuer"); if (Math.floor(now() / 1000) >= claims.exp) throw new Error("expired"); return claims; }; }
This is a sketch to show the steps. In production, use a maintained library (jose’s createRemoteJWKSet and jwtVerify, or supabase-js’s getClaims), which also handles key rotation, nbf, audiences and clock skew. The pitfalls of hand-rolled checks are in verifying JWTs in Node.js.
What did the test show?
JWKS fetches: 1; mean local verify: 60 µs (1,000 requests with one token) signed out, token still accepted for 3600 s expired and tampered tokens are rejected
- One JWKS fetch for 1,000 requests. The keys are cached in the process, so the auth server isn’t involved after the first request.
- About 60 µs per verification for ES256 with WebCrypto on Node.js 24 (64 µs on Node.js 20), far less than any network round-trip.
- Expired and edited tokens fail: a token with
expin the past gets “expired”, and a payload changed to"sub": "admin"gets “bad signature”. - Signing out doesn’t revoke the token. The test marks the session as signed out and the token still verifies, because nothing in the token changed.
What do you give up?
- Revocation waits for
exp. A stolen or signed-out token works until it expires. Keep access tokens short (Supabase defaults to an hour) and rely on refresh tokens, which the auth server does check. In the CRM this didn’t widen the exposure: every database query already ran through Supabase’s REST layer with the same token, and that layer accepts it untilexptoo. - Per-request account checks must move. If “is this user still active?” matters on every request, look it up yourself, as the CRM does with its
profilesrow. - Ephemeral runtimes lose the cache. A function that starts fresh for each invocation fetches the JWKS each time; supabase-js notes Supabase serves that endpoint from an edge cache for this case.
- Symmetric secrets can’t be verified this way without sharing the secret with every service. supabase-js’s
getClaimsfalls back to the network check for HS256 projects, so moving to asymmetric keys is the actual change.
Summary
- With ES256 or RS256 tokens, verify the signature locally against a cached JWKS: one fetch, then microseconds per request.
- Still check
iss,exp(andaud), and choose the algorithm yourself. - The cost: sign-out and revocation take effect at
exp, so keep access tokens short and check account status separately if it matters per request. - In Supabase,
auth.getClaims()does local verification with asymmetric keys and falls back togetUser()for symmetric ones.
Switching to local verification broke one test in the same project, because the test faked the clock: two test assumptions that broke on a real database. For the same idea applied to share links, where one counter revokes everything at once, see revoking share links with a generation counter, and for building an OAuth server in the first place, a secure MCP server with OAuth 2.1.
Part of the guide Reliable backends in Node.js, Python and Go, which puts related articles in reading order.