Skip to main content
Sealgap

What is a JSON Web Token (JWT)?

A JSON Web Token, usually shortened to JWT, is a small piece of text that tells a server who is making a request and what they are allowed to do. The server can trust it because it is signed: if anyone changes a single character, the signature no longer matches. The format is defined in RFC 7519.

What one looks like

A JWT is three parts joined by dots: a header, a payload and a signature. The first two are encoded, not encrypted, which is why so many tokens start with the same characters, eyJ. Anyone who has a token can decode it and read the payload. The signature only proves that the payload has not been changed since it was issued.

That has a practical consequence. A JWT should never carry anything secret in its payload, and a token found in an app's code or in a log can be read to see exactly what it grants.

How Supabase uses JWTs

When a user signs in to a Supabase app, they get an access token, which is a JWT. The app sends it with every request, and the database reads it before applying the Row Level Security policies. According to the Supabase guide to JWTs, the claims that matter most are:

  • sub: the user's ID. Policies compare it with the owner column of each row, usually through auth.uid().
  • role: the database role to use, normally authenticated for a signed-in user.
  • exp: when the token stops being valid. Access tokens are short-lived and renewed by the app in the background.

Some apps also read other claims in their policies, such as is_anonymous for users who came in through anonymous sign-in.

Keys that are JWTs

Supabase's older project keys, the anon key and the service role key, are long-lived JWTs. They look alike at a glance, both starting with eyJ, but their payloads differ in one word: the role. Decoding a key found in an app's code shows at once whether it is the harmless one or the one that skips every access rule. The newer publishable and secret keys are short strings that are not JWTs, and their prefixes say which is which.

What to keep in mind

  • A valid token proves who is asking. It does not prove they should get what they ask for; that is the access rules' job.
  • Do not paste a live user's token or a secret key into an online decoder. Decoding takes one line in a terminal or the browser's console.
  • A token sent to the wrong server can be used by that server until it expires. Short lifetimes limit the damage, which is why access tokens are renewed so often.

Also known as

JWT access token session token bearer token

Free check

See what one of your apps answers.

Certificate, browser protections and keys in public code. No account needed.

See what one of your own apps answers.

The free check looks at an app from the outside: whether it answers, its certificate, its browser protections and keys in its public code.