Skip to main content

Server-Side Setup

1. Configure BetterAuth

2. Database Schema

The authentication system uses the following Prisma schema:

Client-Side Implementation

1. Auth Client Setup

2. Sign Up Form

3. Login Form

4. Password Reset Flow

Authentication Flows

1. Sign Up Flow

  1. User enters name, email, and password
  2. Form validation
  3. Create user account
  4. Send verification email
  5. User verifies email
  6. Auto sign-in after verification

2. Login Flow

  1. User enters email and password
  2. Form validation
  3. Verify credentials
  4. Create session
  5. Redirect to dashboard

3. Password Reset Flow

  1. User requests password reset
  2. Send reset email
  3. User clicks reset link
  4. Enter new password
  5. Update password
  6. Sign in with new password

Security Features

  1. Password Security
    • Secure password hashing
    • Password complexity requirements
    • Rate limiting for failed attempts
  2. Email Verification
    • Secure token generation
    • Token expiration
    • One-time use tokens
  3. Session Security
    • Secure session storage
    • Session timeout
    • IP and user agent tracking

Best Practices

  1. Error Handling
    • Show user-friendly error messages
    • Log authentication errors
    • Handle edge cases
  2. User Experience
    • Clear form validation
    • Loading states
    • Success/error feedback
  3. Security
    • HTTPS in production
    • Rate limiting
    • Input validation

Next Steps