When to use auth collections
Use auth collections when you need to:- Manage user accounts with email/password authentication
- Implement OAuth2 social login (Google, Facebook, GitHub, etc.)
- Support email verification and password resets
- Enable multi-factor authentication (MFA)
- Implement one-time password (OTP) authentication
- Control user sessions and tokens
You can have multiple auth collections in the same app to support different user types (customers, admins, vendors, etc.).
Creating an auth collection
Create an auth collection using the factory function:- Type set to
"auth" - All default auth fields (
email,password,verified, etc.) - Default authentication configuration
- Token generation settings
Default auth fields
Auth collections automatically include these system fields:- id
- email
- password
- emailVisibility
- verified
- tokenKey
Primary key field (same as base collections).
Authentication configuration
Auth collections have extensive configuration options:Password authentication
IdentityFields specifies which fields can be used to identify users during login. You can add custom fields:
Identity fields must have a unique index to be used for authentication.
OAuth2 configuration
Enable social login with OAuth2 providers:Map OAuth2 fields to user fields
Multi-factor authentication (MFA)
One-time password (OTP)
Token configuration
Configure various token lifetimes:Complete example
Here’s a comprehensive example of setting up a users collection:Auth rule vs API rules
Auth collections have a specialAuthRule in addition to the standard API rules:
- AuthRule
- ManageRule
- Standard rules
Applied after successful authentication, before returning the auth token.
Email templates
Customize email templates for various authentication flows:Verification email
Password reset email
Email change confirmation
Available placeholders
{APP_NAME}- Your application name{APP_URL}- Your application URL{TOKEN}- The verification/reset token{OTP}- The one-time password (OTP emails only)
Auth alerts
Notify users when they log in from a new device:Working with auth records
Auth records work like regular records but with additional auth-specific methods:Best practices
- Security
- User experience
- Data management
- Always use HTTPS in production
- Set appropriate token durations
- Enable email verification for sensitive apps
- Use MFA for admin accounts
- Implement rate limiting on auth endpoints
Next steps
Base collections
Learn about standard collections
Fields reference
Explore all field types
Authentication
Implement auth in your app
API rules
Secure your collections