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)
Authentication methods
PocketBase supports multiple authentication strategies:Password authentication
The traditional username/password authentication:OAuth2 authentication
Support for third-party OAuth2 providers:- GitHub
- GitLab
- Discord
- Microsoft
- Spotify
- Kakao
- And more…
One-time password (OTP)
Passwordless authentication via email:Multi-factor authentication (MFA)
Add an extra layer of security with TOTP-based MFA: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:- Change password without providing the old one
- Update email without verification
- Modify the
verifiedfield directly - Update
emailVisibilityand 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
Email verification
Token key management
Auth alerts
Notify users of new login attempts:Email templates
Customize authentication emails:Verification email
Password reset email
Email change confirmation
{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:Security best practices
Use strong password requirements
Use strong password requirements
Configure minimum password length and complexity in your password field settings. The default minimum is 8 characters.
Enable email verification
Enable email verification
Require email verification before allowing full access to your application. Use auth rules like
verified = true.Implement rate limiting
Implement rate limiting
Protect authentication endpoints from brute force attacks by implementing rate limiting in your hooks.
Use HTTPS in production
Use HTTPS in production
Always use HTTPS in production to protect authentication tokens and credentials during transmission.
Rotate token secrets carefully
Rotate token secrets carefully
Changing token secrets (like
AuthToken.Secret) invalidates all existing tokens. Plan token rotation during low-traffic periods.Enable MFA for sensitive operations
Enable MFA for sensitive operations
Consider requiring MFA for users with elevated privileges or access to sensitive data.
Monitor auth alerts
Monitor auth alerts
Enable auth alerts to help users detect unauthorized access attempts.
Validate identity fields
Validate identity fields
When using custom identity fields (like username), ensure they have unique constraints to prevent impersonation.