Skip to main content
Convex provides built-in authentication that works with any OpenID Connect (OIDC) provider or custom JWT tokens. Configure authentication in auth.config.ts and access user identity in your functions.

Configuration

Define your authentication providers in auth.config.ts:

Auth config

The AuthConfig type defines authentication configuration:
AuthProvider[]
An array of authentication providers allowed to issue JWTs for your app.

Auth providers

Convex supports two types of authentication providers:

OIDC provider

string
The domain of the OIDC auth provider.
string
Tokens issued by the auth provider must have this application ID in their audiences.

Custom JWT provider

'customJwt'
Indicates this is a custom JWT provider.
string
The issuer of the JWT auth provider (e.g., https://auth.example.com).
string
The URL to fetch the JWKS (JSON Web Key Set) for token verification.
'RS256' | 'ES256'
The algorithm used to sign JWT tokens. Convex currently supports RS256 and ES256.
string
Tokens must have this application ID in their audiences. Warning: Omitting applicationID is often insecure.

User identity

Access authenticated user information via ctx.auth in queries, mutations, and actions.

Get user identity

UserIdentity interface

The UserIdentity object contains information derived from the JWT token. Only tokenIdentifier and issuer are guaranteed to be present - all other fields depend on what the identity provider includes.

Standard fields

These fields are derived from OpenID Connect (OIDC) standard claims:
string
A stable and globally unique string for this identity. No other user, even from a different provider, will have the same string. Derived from JWT claims sub + iss.
string
Identifier for the end-user from the identity provider, not necessarily unique across different providers. JWT claim: sub.
string
The hostname of the identity provider used to authenticate this user. JWT claim: iss.
string
The user’s full name. JWT claim: name.
string
The user’s given (first) name. JWT claim: given_name.
string
The user’s family (last) name. JWT claim: family_name.
string
The user’s nickname or username. JWT claim: nickname.
string
The user’s preferred username. JWT claim: preferred_username.
string
URL of the user’s profile page. JWT claim: profile.
string
URL of the user’s profile picture. JWT claim: picture.
string
The user’s email address. JWT claim: email.
boolean
Whether the email address has been verified. JWT claim: email_verified.
string
The user’s gender. JWT claim: gender.
string
The user’s birthday. JWT claim: birthdate.
string
The user’s timezone. JWT claim: zoneinfo.
string
The user’s preferred language. JWT claim: locale.
string
The user’s phone number. JWT claim: phone_number.
boolean
Whether the phone number has been verified. JWT claim: phone_number_verified.
string
The user’s address. JWT claim: address.
string
When the user’s information was last updated. JWT claim: updated_at.

Custom claims

Any additional custom claims from your JWT are also available. Type assert them if you know their type:

Auth interface

The Auth interface is available as ctx.auth in all Convex functions:

getUserIdentity

Get details about the currently authenticated user:
Returns: A UserIdentity object if the Convex client was configured with a valid ID token, otherwise:
  • Returns null in queries, mutations, and actions
  • Throws in HTTP actions

Common patterns

Require authentication

Throw an error if the user is not authenticated:
Store the tokenIdentifier to link documents to users:

Role-based access control

Implement custom roles using custom JWT claims:

Best practices

  • Always check authentication when required - getUserIdentity() can return null.
  • Use tokenIdentifier for user linking - It’s stable and globally unique.
  • Configure applicationID - Omitting it in custom JWT providers is often insecure.
  • Store minimal user data - Only store what you need from the identity in your database.
  • Use internal mutations for admin operations - Don’t expose sensitive operations as public functions.