Skip to main content
PocketBase provides a flexible authentication system for auth collections. You can enable multiple authentication methods and configure them based on your application needs.

Authentication methods

PocketBase supports several authentication methods that can be enabled independently:

Email/Password

Traditional authentication using email and password with customizable identity fields

OAuth2

Social login with 15+ providers including Google, GitHub, and Facebook

OTP

One-time password authentication via email for passwordless login

MFA

Multi-factor authentication requiring two different auth methods

Auth collection configuration

Every auth collection has an authRule that you can use to specify additional constraints applied after record authentication and before returning the auth token response to the client.
The authRule check happens in RecordAuthResponse after the initial authentication succeeds but before the token is issued.

Authentication flow

The typical authentication flow in PocketBase follows these steps:
1

Retrieve auth methods

Client calls GET /api/collections/{collection}/auth-methods to discover available authentication methods.
2

Authenticate user

Client submits credentials using one of the enabled methods (password, OAuth2, or OTP).
3

Auth rule validation

PocketBase validates the record against the collection’s authRule if configured.
4

MFA check (optional)

If MFA is enabled and required for the user, PocketBase returns an mfaId instead of the auth token.
5

Second factor (MFA)

If MFA is required, client authenticates again using a different method with the mfaId parameter.
6

Receive token

PocketBase returns the auth token and record data upon successful authentication.

Auth response structure

Successful authentication returns a JSON response with the following structure:
The meta field contains additional provider-specific information (e.g., OAuth2 user data).

Token configuration

Auth collections have several token configurations that control the lifetime and security of various tokens: Each token configuration includes:
  • Secret: Random 50-character string for signing tokens (minimum 30 characters)
  • Duration: Token validity period in seconds (minimum 10s, maximum ~3 years)

Auth alerts

PocketBase can send email alerts when users authenticate from new devices or locations. This feature helps users detect unauthorized access to their accounts.
Auth alerts are only sent after the first successful login. The system tracks up to 5 authentication origins per user based on IP address and user agent fingerprints.

Security features

Rate limiting

All authentication endpoints include rate limiting to prevent brute force attacks:

Token key rotation

Every auth record has a tokenKey field that is used to sign auth tokens. When the password changes, the token key is automatically refreshed, invalidating all existing sessions:

Email verification

Auth records track email verification status. OAuth2 and OTP authentication can automatically verify emails:

Manage rule

The manageRule gives admin-like permissions for auth records, allowing operations like:
  • Changing passwords without requiring the old password
  • Directly updating the verified state
  • Modifying the email without confirmation
  • Ignoring email visibility settings
The manage rule is executed in addition to the Create and Update API rules. Be careful when setting this rule as it grants elevated permissions.

Common endpoints

All auth collections automatically get the following endpoints:

Next steps

Email/Password auth

Configure traditional password authentication

OAuth2 providers

Set up social login providers

API rules

Learn about access control

MFA setup

Enable multi-factor authentication