Skip to main content
TrailBase provides built-in authentication with support for password-based login, OAuth providers, email verification, and password reset flows.

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:
Do not modify the _user table directly. Use TrailBase’s auth APIs and CLI commands instead.

Password Authentication

Enable Password Auth

Password authentication is enabled by default. Configure it in traildepot/config.textproto:
traildepot/config.textproto

User Registration

If email verification is enabled, users must click the verification link in their email before logging in.

User Login

Token Management

The client automatically handles token storage and refresh:

Session Persistence

Tokens are stored in localStorage (browser) or secure storage (mobile):

OAuth Providers

TrailBase supports multiple OAuth providers:
  • Google
  • GitHub
  • Discord
  • Microsoft
  • GitLab
  • And more…

Configure OAuth Provider

1

Register OAuth Application

Create an OAuth app with your provider:GitHub:
  1. Go to Settings → Developer settings → OAuth Apps
  2. Click “New OAuth App”
  3. Set callback URL: http://localhost:4000/_/auth/oauth/callback/github
  4. Save Client ID and Client Secret
Google:
  1. Go to Google Cloud Console
  2. Create a new project
  3. Enable Google+ API
  4. Create OAuth 2.0 credentials
  5. 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

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
OAuth redirects will now work with 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
Expose via API:
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