On this page

Roles and JWTs

Every request runs as a database role chosen from its key and token. Access tokens are JWTs signed with your project's secret.

#Roles

RoleUsed when
anonA request uses the anon key without a signed-in user
authenticatedA request carries a signed-in user's access token
service_roleA request uses the service_role key. It bypasses Row Level Security, so keep it on the server.

#Token claims

ClaimValue
subThe user id (auth.uid())
roleauthenticated for users; the anon and service_role keys carry anon and service_role
audauthenticated
email, phoneThe user's contact details
app_metadataSet by the server only (provider, providers); safe for authorization
user_metadataSet by the user with updateUser({ data }); never trust it for authorization
aal, amrAssurance level (aal1 or aal2) and how the user signed in
session_idThe session the token belongs to
is_anonymoustrue for anonymous users
exp, iatExpiry and issue time

#Token claims in SQL

SQL
select auth.uid(), auth.jwt() ->> 'email', auth.jwt() -> 'app_metadata' ->> 'provider';

#Verify tokens on your server

Access tokens are signed with HS256 using the project's JWT secret. Copy it from the dashboard (project → Settings → API keys) to verify tokens on your own servers, or call auth.getUser(token) to let StitchDB check it:

JavaScript
import { jwtVerify } from 'jose'
const { payload } = await jwtVerify(token, new TextEncoder().encode(process.env.STITCHDB_JWT_SECRET))