Authentication Methods

The boilerplate includes a comprehensive Better Auth system with multiple authentication methods that can be enabled/disabled via environment variables.

Available Authentication Methods

Core Authentication Methods

โœ… Credentials (Email/Password)

Always available - classic email/password login

emailAndPassword: enabled

๐Ÿ”— Magic Link

Passwordless authentication via email

magicLink plugin

๐Ÿ” Two-Factor Authentication

TOTP (apps) + OTP (SMS/email) support

twoFactor plugin

๐ŸŒ Social Authentication

Google, GitHub, Facebook, Apple login

socialProviders (OAuth)

Advanced Authentication Features

๐Ÿ”‘ API Keys

Generate API keys for programmatic access

apiKey plugin

๐ŸŽซ Bearer Tokens

JWT tokens for API authentication

bearer plugin

๐Ÿข Organizations

Multi-tenant workspaces with roles

organization plugin

๐Ÿ‘‘ Admin Functions

Administrative user management

admin plugin

Environment Variables Configuration

Core Requirements: At minimum, you need BETTER_AUTH_SECRET and BETTER_AUTH_URL to get authentication working.

Core Authentication Controls

# Better Auth Core
BETTER_AUTH_SECRET="your-secret-key"
BETTER_AUTH_URL="http://localhost:3000"
BETTER_AUTH_TRUSTED_ORIGINS="http://localhost:3000"

# Email Features (required for magic link, verification, password reset)
RESEND_API_KEY="re_your_api_key"
EMAIL_FROM="noreply@yourdomain.com"

Feature Toggle Variables

# Control which auth methods are available
NEXT_PUBLIC_AUTH_METHODS="credential,magiclink,google,github"
# Options: credential, magiclink, google, github, facebook, apple

Organization & Billing

Billing Mode: Choose between individual user billing or organization-based billing.
# Multi-tenant mode
NEXT_PUBLIC_BILLING_MODE="organization" # or "user"

# Available pages/features
NEXT_PUBLIC_ENABLED_PAGES="organization,invitation,account,settings,subscription,notifications,admin"

Quick Configuration Examples

1

Minimal Setup (Email/Password only)

BETTER_AUTH_SECRET="your-secret"
BETTER_AUTH_URL="http://localhost:3000"
NEXT_PUBLIC_AUTH_METHODS="credential"
NEXT_PUBLIC_BETTER_AUTH_REQUIRE_EMAIL_VERIFICATION=false
2

Full Features Setup

# Core
BETTER_AUTH_SECRET="your-secret"
BETTER_AUTH_URL="http://localhost:3000"

# Email service
RESEND_API_KEY="re_your_key"
EMAIL_FROM="noreply@yourdomain.com"

# All auth methods
NEXT_PUBLIC_AUTH_METHODS="credential,magiclink,google,github"

# All user features
NEXT_PUBLIC_BETTER_AUTH_REQUIRE_EMAIL_VERIFICATION=true
NEXT_PUBLIC_BETTER_AUTH_2FA_ENABLE=true
NEXT_PUBLIC_BETTER_AUTH_TOKEN_MANAGEMENT=true

# Social providers
GOOGLE_CLIENT_ID="your-google-id"
GOOGLE_CLIENT_SECRET="your-google-secret"
GITHUB_CLIENT_ID="your-github-id"
GITHUB_CLIENT_SECRET="your-github-secret"

File Structure & User Pages

All authentication features are organized in dedicated route groups and component folders for easy navigation and maintenance.

๐Ÿ“ Authentication Routes

Location: src/app/[locale]/(auth)/All public authentication pages grouped under a dedicated layout.
src/app/[locale]/(auth)/
โ”œโ”€โ”€ login/                        # Login page with all methods
โ”œโ”€โ”€ register/                     # User registration
โ”œโ”€โ”€ logout/                       # Logout confirmation
โ”œโ”€โ”€ reset-password/               # Password reset form
โ””โ”€โ”€ verify-request/               # Email & 2FA verification
    โ”œโ”€โ”€ totp/                     # TOTP verification
    โ”œโ”€โ”€ otp/                      # OTP verification
    โ””โ”€โ”€ recovery/                 # Recovery codes verification

๐Ÿงฉ Authentication Components

Location: src/components/features/auth/Reusable authentication form components used across all auth pages.
src/components/features/auth/
โ””โ”€โ”€ forms/                        # All authentication forms
    โ”œโ”€โ”€ login.tsx                 # Main login form
    โ”œโ”€โ”€ credential-form.tsx       # Email/password form
    โ”œโ”€โ”€ magic-link-form.tsx       # Magic link form
    โ”œโ”€โ”€ register-form.tsx         # Registration forms
    โ””โ”€โ”€ recovery-code-form.tsx    # 2FA recovery form

๐Ÿ‘ค User Account Management

Location: src/app/[locale]/(app)/account/Protected pages requiring user authentication. Access controlled by auth middleware.
src/app/[locale]/(app)/account/
โ”œโ”€โ”€ settings/                     # Profile & security settings
โ”œโ”€โ”€ api-keys/                     # API key management
โ”œโ”€โ”€ subscription/                 # Subscription management
โ”œโ”€โ”€ notifications/                # Notification preferences
โ”œโ”€โ”€ organizations/                # Organization management
โ”‚   โ””โ”€โ”€ [id]/                     # Organization details & settings
โ””โ”€โ”€ invitations/                  # Organization invitations
    โ””โ”€โ”€ [id]/                     # Accept/decline invitations

Method-Specific Documentation

Ready to dive deeper? Each authentication method has its own detailed guide with configuration examples and troubleshooting tips.
Security First: All authentication methods include built-in rate limiting, CSRF protection, secure session management, and XSS prevention.
    Authentication Methods | ShipSaaS Documentation | ShipSaaS - Launch your SaaS with AI in days