Authentication
Authentication with Better-auth.
This template uses Better-auth for authentication. For more information, go to Better-auth docs
Key Features
🔐
Multiple Providers
Google, GitHub, Apple, Magic Link, Email/Password
📧
Passwordless
Email magic links authentication
🛡️
Security
Rate limiting protection
🔄
Multiple Sessions
Robust session management
⚡
Server-Side
Authentication helpers
🔗
Account Linking
Link accounts using OAuth
Setup Guide
1. Environment Variables
Create or update your .env.local
file:
.env.local
Terminal
2. Auth Configuration
Set up your authentication configuration in lib/auth.ts
:
lib/auth.ts
TYPESCRIPT
Usage Examples
Protected API Routes
TYPESCRIPT
Protected Pages
TYPESCRIPT
Getting Current User
TYPESCRIPT
Security Features
Rate Limiting
Protection against brute force attacks and abuse
TYPESCRIPT
Best Practices
Environment Variables
- 1Never commit sensitive credentials
- 2Use different values for development and production
- 3Regularly rotate secrets
Security
- 1Keep dependencies updated
- 2Implement proper CORS policies
- 3Use HTTPS in production
- 4Enable rate limiting
User Experience
- 1Provide clear error messages
- 2Implement proper loading states
- 3Add remember me functionality
- 4Support multiple auth methods