Authentication Setup
Budget Bee uses Better Auth for authentication, providing email/password and social login with Google.Overview
Better Auth provides:- Email & Password authentication with verification
- OAuth integration (Google Sign-In)
- Account linking across auth methods
- Session management with JWT tokens
- Organization support for multi-tenant features
- Password reset via email
Configuration
Authentication is configured inpackages/core/auth.ts:
Email & Password Authentication
Requirements
Passwords must meet these criteria:Password Requirements
Password Requirements
- Minimum 8 characters
- At least 1 lowercase letter (a-z)
- At least 1 uppercase letter (A-Z)
- At least 1 number (0-9)
Sign-Up Flow
Sign-In Flow
Password Reset
Google OAuth
Setup Google OAuth
Create Google Cloud Project
- Go to Google Cloud Console
- Create a new project or select existing
- Enable the Google+ API
Create OAuth Credentials
- Navigate to APIs & Services → Credentials
- Click Create Credentials → OAuth 2.0 Client ID
- Select Web application
- Add authorized redirect URIs:
- Development:
http://localhost:3000/api/auth/callback/google - Production:
https://your-domain.com/api/auth/callback/google
- Development:
Google Sign-In Flow
Account Linking
Users can link multiple authentication methods:- User signs up with email/password, later links Google account
- User signs in with Google, account automatically created
- Existing email account automatically links to Google if emails match
Session Management
Custom Session Data
Budget Bee extends sessions with subscription information:JWT Tokens
JWT tokens include user and organization context:Session Storage
Sessions are stored in the database:Organization Plugin
Better Auth’s organization plugin enables multi-tenancy:Email Templates
Budget Bee sends these emails:Verification Email
Password Reset Email
Organization Invitation Email
See Invitations for invitation email template.Security Features
Email Verification
Prevents unauthorized account creation and spam.
Password Hashing
Passwords hashed with bcrypt before storage.
JWT Tokens
Stateless authentication with signed tokens.
Session Tracking
Track all active sessions with IP and user agent.
Client-Side Usage
Using the auth client in React components:Troubleshooting
Verification email not received
Verification email not received
Check:
- Resend API key is valid
- Sender email is verified in Resend
- Check spam/junk folder
- Review Resend dashboard for delivery logs
- Verify SMTP_MAIL and SMTP_SENDER_NAME are set
Google Sign-In not working
Google Sign-In not working
Verify:
- Client ID and secret are correct
- Redirect URI matches exactly (including protocol)
- Google+ API is enabled in Google Cloud Console
- OAuth consent screen is configured
Session expired quickly
Session expired quickly
Ensure:
- Browser cookies are enabled
- BETTER_AUTH_SECRET hasn’t changed
- JWT expiration time is appropriate (default 1h)
- System clock is accurate
Cannot create organization
Cannot create organization
Check:
- User email is verified
- User has active Teams subscription
- Haven’t reached organization limit (5)
- Subscription admin database user has correct permissions
Next Steps
Environment Variables
Configure all authentication-related environment variables.
Database Setup
Set up database tables and users for authentication.

