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

  • 1
    Never commit sensitive credentials
  • 2
    Use different values for development and production
  • 3
    Regularly rotate secrets

Security

  • 1
    Keep dependencies updated
  • 2
    Implement proper CORS policies
  • 3
    Use HTTPS in production
  • 4
    Enable rate limiting

User Experience

  • 1
    Provide clear error messages
  • 2
    Implement proper loading states
  • 3
    Add remember me functionality
  • 4
    Support multiple auth methods

Additional Resources