Authentication
Built-in authentication powered by Better Auth. Configure strategies, roles, two-factor authentication, and email templates.
Basic Setup
Start with the simplest auth config: email and password with a default role.
auth:
strategies:
- type: emailAndPassword
defaultRole: memberStrategies
Choose one or more authentication strategies to offer your users.
Strategy Options
Each strategy type accepts additional configuration properties.
auth:
strategies:
- type: emailAndPassword
minPasswordLength: 12
requireEmailVerification: true
- type: magicLink
expirationMinutes: 30Allow Sign-Up
Controls whether users can self-register. Set to false to restrict user creation to admins only.
auth:
allowSignUp: false
strategies:
- type: emailAndPasswordAdding OAuth
Add social login providers alongside emailAndPassword. Multiple strategies can coexist.
auth:
strategies:
- type: emailAndPassword
- type: magicLink
- type: oauth
providers:
- google
- githubEnvironment variables required
OAuth providers require AUTH_SECRET and provider-specific CLIENT_ID / CLIENT_SECRET environment variables.
Roles & Permissions
Three built-in roles: admin, member, viewer. Define custom roles with name, description, and optional level (hierarchy ordering). Set defaultRole for new users. First user automatically becomes admin.
auth:
strategies:
- type: emailAndPassword
defaultRole: member
roles:
- name: editor
description: Can edit content
level: 30
- name: reviewer
description: Can approve changes
level: 20admin
Full access to all features, user management, and settings.
member
Can create, read, and update records. Cannot manage users.
viewer
Read-only access. Cannot create or modify records.
Two-Factor Auth
Optional TOTP-based 2FA. Enable with twoFactor: true or pass an object with issuer, backupCodes, digits, and period options.
# Boolean shorthand
auth:
strategies:
- type: emailAndPassword
twoFactor: true
# Object form with options
auth:
strategies:
- type: emailAndPassword
twoFactor:
issuer: "MyApp"
backupCodes: true
digits: 6
period: 30Email Templates
Customizable emails for verification, resetPassword, magicLink, emailOtp, twoFactorBackupCodes, welcome, and accountDeletion. Supports $name, $url, $email variable substitution in subject and text.
auth:
strategies:
- type: emailAndPassword
emailTemplates:
verification:
subject: "Verify your email, $name"
text: "Click here to verify: $url"
resetPassword:
subject: "Reset your password"
text: "Hi $name, reset here: $url"
magicLink:
subject: "Your sign-in link"
text: "Click to sign in: $url"
emailOtp:
subject: "Your one-time code"
text: "Your code is: $code"
twoFactorBackupCodes:
subject: "Your backup codes"
text: "Save these backup codes: $codes"
welcome:
subject: "Welcome to $organizationName"
text: "Hi $name, welcome aboard!"
accountDeletion:
subject: "Account deletion confirmation"
text: "Hi $name, your account has been deleted."