Better Auth
Let people who sign in with Better Auth call your API. Its JWT plugin signs a token, and your API verifies it against the plugin's public keys.
Better Auth keeps sessions in a cookie on your app's own domain. An API on another server or another domain cannot read that cookie. Better Auth's JWT plugin signs a short-lived token for the session instead, and your API verifies it with @kizunajs/jwt.
Turn on the JWT plugin
Name your API as the token's audience. Without it, the audience is your app's own URL:
The plugin serves its public keys at /api/auth/jwks and signs with EdDSA. A token lasts 15 minutes.
Declare the identity
The issuer is your app's origin, the baseURL above:
sub is the user's id, and the other claims are the session's user, like email and name.
Send the token
The app asks Better Auth for a token, and sends it before every request:
Each call asks for a fresh token. Keep the token until shortly before its exp to save the round trip.
Roles
A role on the user, like the one Better Auth's admin plugin adds, arrives as a claim:
To choose the claims yourself, set jwt.definePayload on the plugin.
Other clients and AI assistants
For apps you do not own, like an MCP client, Better Auth's OAuth provider issues tokens with scopes. OAuth covers that setup.