Skip to main content
PocketBase provides a comprehensive authentication system with support for multiple authentication methods, token management, and fine-grained access control through API rules.

Auth collections

Authentication in PocketBase is built around auth collections - specialized collections with built-in authentication features.

Creating auth collections

Built-in auth fields

Every auth collection automatically includes:
  • id - Unique identifier (15 chars, unique across all auth collections)
  • email - Email address with unique constraint
  • emailVisibility - Controls public visibility of email
  • verified - Email verification status
  • password - Bcrypt-hashed password (never returned in API responses)
  • tokenKey - Session token secret (never returned in API responses)
Auth collection IDs must be unique across all auth collections to prevent authentication conflicts.

Authentication methods

PocketBase supports multiple authentication strategies:

Password authentication

The traditional username/password authentication:
Identity fields determine which fields can be used for login. Users can authenticate with any configured identity field.

OAuth2 authentication

Support for third-party OAuth2 providers:
Supported providers:
  • Google
  • Facebook
  • GitHub
  • GitLab
  • Discord
  • Twitter
  • Microsoft
  • Spotify
  • Kakao
  • And more…

One-time password (OTP)

Passwordless authentication via email:
Users receive a one-time code via email that they use to authenticate.

Multi-factor authentication (MFA)

Add an extra layer of security with TOTP-based MFA:
Users can enable MFA on their accounts and must provide a time-based code after password authentication.

Auth rules

Auth rules provide additional constraints beyond password/OAuth2 verification:
Auth rules are evaluated after successful password/OAuth2 verification and before issuing the auth token.

Manage rules

Manage rules grant admin-like permissions for auth operations:
With manage rule access, users can:
  • Change password without providing the old one
  • Update email without verification
  • Modify the verified field directly
  • Update emailVisibility and other protected fields

Token configuration

Auth collections use multiple token types for different purposes:

Auth token

Issued after successful authentication:

Password reset token

For password recovery:

Email change token

For confirming email address changes:

Verification token

For email verification:

File token

For accessing protected files:
Token secrets are automatically generated and rotated when needed. Never expose these secrets publicly.

Working with auth records

Creating users

Password management

Setting a new password automatically refreshes the tokenKey, invalidating all existing auth tokens for that user.

Email verification

Token key management

Auth alerts

Notify users of new login attempts:
Users receive an email when they log in from a new device or location.

Email templates

Customize authentication emails:

Verification email

Password reset email

Email change confirmation

Available template variables:
  • {APP_URL} - Your application URL
  • {APP_NAME} - Your application name
  • {TOKEN} - The verification/reset token
  • {ACTION_URL} - Pre-built action URL

Authentication in API requests

Request context

Auth records are available in the request context:

API rules context

Access auth data in API rules:
See API Rules for more details.

Security best practices

Configure minimum password length and complexity in your password field settings. The default minimum is 8 characters.
Require email verification before allowing full access to your application. Use auth rules like verified = true.
Protect authentication endpoints from brute force attacks by implementing rate limiting in your hooks.
Always use HTTPS in production to protect authentication tokens and credentials during transmission.
Changing token secrets (like AuthToken.Secret) invalidates all existing tokens. Plan token rotation during low-traffic periods.
Consider requiring MFA for users with elevated privileges or access to sensitive data.
Enable auth alerts to help users detect unauthorized access attempts.
When using custom identity fields (like username), ensure they have unique constraints to prevent impersonation.