Overview
TrailBase authentication features:- Password authentication - Email and password login with configurable policies
- OAuth providers - Google, GitHub, Discord, Microsoft, and more
- Email verification - Confirm user email addresses
- Password reset - Secure password recovery via email
- Session management - JWT tokens with refresh tokens
- Admin accounts - Special privileges for administrative users
User Table
TrailBase includes a built-in_user table:
Password Authentication
Enable Password Auth
Password authentication is enabled by default. Configure it intraildepot/config.textproto:
traildepot/config.textproto
User Registration
- TypeScript Client
- Dart/Flutter
- cURL
If email verification is enabled, users must click the verification link in their email before logging in.
User Login
- TypeScript Client
- Dart/Flutter
- cURL
Token Management
The client automatically handles token storage and refresh:Session Persistence
Tokens are stored inlocalStorage (browser) or secure storage (mobile):
OAuth Providers
TrailBase supports multiple OAuth providers:- GitHub
- Discord
- Microsoft
- GitLab
- And more…
Configure OAuth Provider
1
Register OAuth Application
Create an OAuth app with your provider:GitHub:
- Go to Settings → Developer settings → OAuth Apps
- Click “New OAuth App”
- Set callback URL:
http://localhost:4000/_/auth/oauth/callback/github - Save Client ID and Client Secret
- Go to Google Cloud Console
- Create a new project
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized redirect URI:
http://localhost:4000/_/auth/oauth/callback/google
2
Add Provider to Config
Edit
traildepot/config.textproto:traildepot/config.textproto
3
Restart TrailBase
OAuth Login Flow
- Web (Redirect)
- Mobile (PKCE)
- Direct URL
Mobile Apps: Use PKCE (Proof Key for Code Exchange) for secure OAuth flows without exposing client secrets.
Custom URI Schemes (Mobile)
For mobile apps, configure custom URI schemes:traildepot/config.textproto
myapp://auth/callback.
Email Verification
Send Verification Email
After registration, TrailBase automatically sends a verification email if configured:traildepot/config.textproto
Verify Email Manually
Users can request a new verification email:CLI Verification
For development, verify users via CLI:Password Reset
Request Password Reset
Reset Password with Token
The reset email contains a link with a token. Users submit a new password:User Management CLI
Manage users via the CLI:Create Admin User
List Admin Users
Promote/Demote Users
Change User Password
Change User Email
Delete User
Invalidate Sessions
Force a user to re-login:Mint Auth Token
Generate an auth token for a user (useful for automation):Access Control
Protect your Record APIs with authentication:traildepot/config.textproto
Row-Level Access Control
Restrict access to specific rows:traildepot/config.textproto
Complex Access Rules
Use SQL expressions for advanced access control:traildepot/config.textproto
Access Rule Variables:
_USER_.id- Current user’s ID_USER_.email- Current user’s email_USER_.admin- Whether user is admin_ROW_.*- Column values from the row being accessed_REQ_.*- Values from the request body (for CREATE/UPDATE)
User Profiles
Extend user data with a profiles table:migrations/main/U1234567890__create_profiles.sql
traildepot/config.textproto
Avatar Uploads
TrailBase provides built-in avatar support:Next Steps
First App
Add auth to your first app
Database Setup
Link users with your tables
File Uploads
Handle user file uploads
CLI Usage
Manage users via CLI