https://github.com/AntonioErdeljac/next-auth-v5-advanced-guideNext Auth v5 - Advanced Guide (2024)

This is a repository for Next Auth v5 - Advanced Guide (2024)
VIDEO TUTORIAL
Key Features:
- ๐ Next-auth v5 (Auth.js)
- ๐ Next.js 14 with server actions
- ๐ Credentials Provider
- ๐ OAuth Provider (Social login with Google & GitHub)
- ๐ Forgot password functionality
- โ๏ธ Email verification
- ๐ฑ Two factor verification
- ๐ฅ User roles (Admin & User)
- ๐ Login component (Opens in redirect or modal)
- ๐ Register component
- ๐ค Forgot password component
- โ
Verification component
- โ ๏ธ Error component
- ๐ Login button
- ๐ช Logout button
- ๐ง Role Gate
- ๐ Exploring next.js middleware
- ๐ Extending & Exploring next-auth session
- ๐ Exploring next-auth callbacks
- ๐ค useCurrentUser hook
- ๐ useRole hook
- ๐ง currentUser utility
- ๐ฎ currentRole utility
- ๐ฅ๏ธ Example with server component
- ๐ป Example with client component
- ๐ Render content for admins using RoleGate component
- ๐ก๏ธ Protect API Routes for admins only
- ๐ Protect Server Actions for admins only
- ๐ง Change email with new verification in Settings page
- ๐ Change password with old password confirmation in Settings page
- ๐ Enable/disable two-factor auth in Settings page
- ๐ Change user role in Settings page (for development purposes only)
Prerequisites
Node version 18.7.x
Cloning the repository
git clone https://github.com/AntonioErdeljac/next-auth-v5-advanced-guide.git
Install packages
Setup .env file
DATABASE_URL=
DIRECT_URL=
AUTH_SECRET=
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
RESEND_API_KEY=
NEXT_PUBLIC_APP_URL=
Setup Prisma
npx prisma generate
npx prisma db push
Start the app
Available commands
Running commands with npm npm run [command]
command |
description |
dev |
Starts a development instance of the app |