Overview
Toots uses better-auth for authentication, providing email/password sign-up and login with session management.Configuration
Authentication is configured inapps/web/lib/auth/auth.ts:
apps/web/lib/auth/auth.ts
Required environment variables
Set these variables inapps/web/.env:
- BETTER_AUTH_SECRET - A random secret string for session signing and encryption
- BETTER_AUTH_URL - Your application’s base URL
Database schema
better-auth uses these Prisma models for authentication:User model
schema.prisma
Session model
schema.prisma
Account model
schema.prisma
Verification model
schema.prisma
Authentication features
Email and password
Toots currently supports email/password authentication:- Sign up - Create a new account with email and password
- Sign in - Authenticate with existing credentials
- Session management - Automatic session handling with secure tokens
- Route protection - Middleware to protect authenticated routes
User management
Users are identified by:- Unique email address
- CUID (Collision-resistant Unique Identifier)
- Optional name and profile image
- Email verification status
Route protection
Toots implements route protection to ensure users are authenticated before accessing protected pages:- Public routes - Sign in, sign up pages
- Protected routes - Dashboard, projects, tickets
- Automatic redirects - Unauthenticated users are redirected to sign in
Session security
Sessions are secured with:- Token-based authentication - Unique session tokens
- Expiration - Sessions expire after a configured time period
- IP and user agent tracking - Optional security metadata
- Cascade deletion - Sessions are deleted when users are removed
Password security
better-auth handles password security:- Passwords are hashed using secure algorithms
- Plain text passwords are never stored
- Hashes are stored in the
Accounttable
better-auth automatically handles password hashing and verification. You don’t need to implement this manually.
Production considerations
HTTPS required
In production, always use HTTPS for authentication:.env.production
Secure secrets
Generate a strong secret for production:Environment-specific URLs
Use different URLs for each environment:Future authentication features
better-auth supports additional authentication methods that can be added:- OAuth providers (Google, GitHub, etc.)
- Magic link authentication
- Two-factor authentication
- Social login
- Passkeys
These features are not currently implemented in Toots but can be added through better-auth configuration.
Troubleshooting
Invalid session
If you see session errors:- Check that
BETTER_AUTH_SECRETis set - Verify
BETTER_AUTH_URLmatches your application URL - Clear cookies and sign in again
Database connection errors
Authentication requires a working database connection:- Verify
DATABASE_URLis correct - Run migrations:
pnpm --filter web db:migrate - Check PostgreSQL is running
Next steps
After configuring authentication:- Set up AI integration
- Start the development server
- Test sign up and sign in flows