Authentication
Learn how to implement and configure authentication using Better-auth in your application.
Authentication System
This template uses Better-auth for authentication, providing a modern, secure multi-provider authentication solution.
Key Features
Multiple Providers
🔐 Support for Google, GitHub, Apple, Magic Link, and Email/Password
Passwordless
📧 Email magic links authentication for password-free login
Security
Multiple Sessions
🔄 Robust session management across devices
Server-Side
⚡ Authentication helpers for server components
Account Linking
Setup Guide
1. Environment Variables
Create or update your .env.local
file:
Remember to generate a strong secret key for BETTER_AUTH_SECRET and never commit your .env.local file to version control.
2. Auth Configuration
Set up your authentication configuration in lib/auth.ts
:
Usage Examples
Better-auth makes it easy to protect routes, API endpoints, and check authentication status throughout your application.
Protected API Routes
Protected Pages
Getting Current User
Security Features
Rate Limiting
Protection against brute force attacks and abuse:
Best Practices
Environment Variables
- Never commit sensitive credentials
- Use different values for development and production
- Regularly rotate secrets
Security
- Keep dependencies updated
- Implement proper CORS policies
- Use HTTPS in production
- Enable rate limiting
User Experience
- Provide clear error messages
- Implement proper loading states
- Add remember me functionality
- Support multiple auth methods