Authentication Overview
Minimal’s authentication system includes:- Email/Password: Built-in email and password authentication
- OAuth: Google sign-in (optional)
- Email Verification: Email verification on signup
- Password Reset: Secure password reset flow
- Session Management: 7-day sessions with automatic renewal
- Account Linking: Link multiple OAuth providers to one account
- Chrome Extension: CORS support for browser extension
Better Auth Configuration
Authentication is configured inlib/auth.ts using Better Auth with Prisma adapter.
Core Setup
Required Environment Variables
Email and Password Authentication
Email/password authentication is enabled by default:Features
- Secure password hashing
- Password reset via email
- Email verification
- Account creation with automatic group setup
User Signup Flow
Password Requirements
Better Auth enforces secure password requirements by default. Customize these in your auth configuration if needed.
Email Verification
Email verification is configured to:- Send verification email on signup
- Auto sign-in after verification
- Use custom email templates
Email Service Setup
Minimal uses Autosend for transactional emails:Get Autosend API Key
- Sign up at autosend.com
- Create an API key from the dashboard
Email Templates
Minimal includes three email templates:- Welcome Email: Sent on first signup
- Verification Email: Email verification link
- Reset Password Email: Password reset link
lib/emails/ and use a consistent design from lib/email.ts.
OAuth Configuration
Google OAuth Setup
Create Google OAuth App
- Go to Google Cloud Console
- Create a new project or select existing
- Navigate to “APIs & Services” > “Credentials”
- Click “Create Credentials” > “OAuth client ID”
- Select “Web application”
Configure OAuth Consent Screen
- Navigate to “OAuth consent screen”
- Select “External” (or “Internal” for workspace)
- Fill in required fields:
- App name: “Minimal”
- User support email
- Developer contact email
- Add scopes:
userinfo.emailuserinfo.profile
OAuth Configuration in Code
Google OAuth is conditionally enabled:Account Linking
Minimal supports linking multiple OAuth providers to one account:- Sign in with email/password, then link Google
- Sign in with Google, then add password
- Link multiple OAuth providers (if additional providers are added)
Session Management
Sessions are configured with:- Session Duration: 7 days
- Update Frequency: Session extended every 24 hours of activity
- Storage: Database-backed sessions (session table)
- Security: Tracks IP address and user agent
Session Data
Each session stores:- Session token (unique, indexed)
- User ID
- Expiration timestamp
- IP address (optional)
- User agent (optional)
- Created/updated timestamps
Chrome Extension Support
Minimal supports authentication from a Chrome extension:Configuration
Get Extension ID
After building your Chrome extension, note the extension ID from
chrome://extensionsAuthentication Hooks
Minimal uses Better Auth hooks to perform actions after authentication:Default Group Creation
Every user gets a default “Bookmarks” group:Security Best Practices
Secret Management
- Strong Secret: Generate with
openssl rand -base64 32 - Never Commit: Add
.envto.gitignore - Rotate Regularly: Update
BETTER_AUTH_SECRETperiodically - Environment Separation: Use different secrets for dev/prod
HTTPS Requirements
Better Auth requires HTTPS in production for secure cookie transmission.
- Use HTTPS for
NEXT_PUBLIC_APP_URL - Configure SSL/TLS certificates (Let’s Encrypt recommended)
- Set secure cookie flags automatically in production
OAuth Security
- Verify Redirect URIs: Only add your actual domain
- Restrict Scopes: Only request necessary OAuth scopes
- Secure Secrets: Keep
GOOGLE_CLIENT_SECRETprivate - Review Permissions: Regularly review OAuth app permissions
Troubleshooting
”BETTER_AUTH_SECRET is required”
Set the secret in.env:
OAuth Redirect Mismatch
- Check
NEXT_PUBLIC_APP_URLmatches OAuth redirect URI exactly - Ensure protocol (http/https) is correct
- Verify no trailing slashes in URLs
- Add both development and production URIs to OAuth app
Email Not Sending
- Verify
AUTOSEND_API_KEYis set and valid - Check Autosend dashboard for delivery logs
- Review application logs for email errors
- Test with a known working email address
Session Expired Immediately
- Check server and client clocks are synchronized
- Verify database is correctly storing sessions
- Check
NEXT_PUBLIC_APP_URLmatches your actual domain - Review browser cookie settings (allow cookies)
Chrome Extension CORS Issues
- Verify
CHROME_EXTENSION_IDmatches actual extension ID - Ensure extension is loaded (check
chrome://extensions) - Rebuild application after adding extension ID
- Check browser console for specific CORS errors
User Management
Admin Access
Set admin email for admin privileges:.env
User Roles
Currently, Minimal uses a simple admin check. To extend:- Add
rolefield to user model - Update auth hooks to check roles
- Implement role-based access control in API routes
Next Steps
- Configuration - Complete environment variables guide
- Database Setup - Database configuration
- Installation - Full installation guide