Configuration

Authentication

Configure authentication providers and user management with NextAuth.js.

Overview

The template uses NextAuth.js for authentication, supporting multiple providers and session management out of the box.

Multiple Providers

Support for Google, Discord, GitHub, and email/password.

Secure Sessions

JWT-based sessions with secure cookie handling.

2FA Support

Optional two-factor authentication with TOTP.

Environment Variables

Configure the following environment variables in your .env.local file:

# NextAuth.js
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-key-here

# Google OAuth (optional)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret

# Discord OAuth (optional)
DISCORD_CLIENT_ID=your-discord-client-id
DISCORD_CLIENT_SECRET=your-discord-client-secret

# GitHub OAuth (optional)
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret

Setting up Google OAuth

  1. 1Go to the Google Cloud Console
  2. 2Create a new project or select existing one
  3. 3Navigate to "APIs & Services" → "Credentials"
  4. 4Click "Create Credentials" → "OAuth client ID"
  5. 5Select "Web application" as the application type
  6. 6Add authorized redirect URI: http://localhost:3000/api/auth/callback/google
  7. 7Copy the Client ID and Client Secret to your .env.local

Setting up Discord OAuth

  1. 1Go to the Discord Developer Portal
  2. 2Create a new application
  3. 3Go to "OAuth2" → "General"
  4. 4Add redirect URI: http://localhost:3000/api/auth/callback/discord
  5. 5Copy the Client ID and Client Secret to your .env.local

User Roles

The template includes a role-based access control system:

ADMINFull access to all features and admin panel
MODERATORCan manage content and moderate comments
PREMIUMAccess to premium features and ad-free
USERStandard user access

Protected Routes

Routes are protected using middleware. Configure protected paths in middleware.ts:

// Protected routes require authentication
/library/*
/profile/*
/settings/*

// Admin routes require ADMIN role
/admin/*

Next Steps