🔐Auth & SecurityComing Soon
Authentication & Sessions
NextAuth.js with Google OAuth, credentials login, JWT sessions, and admin role management.
Video coming soon
Add a YouTube video ID to the topics config
Documentation
Overview
Authentication is handled by NextAuth.js v5 (Auth.js) with two providers: Google OAuth and Credentials (email/username + password). Sessions use the JWT strategy for stateless auth.
Auth Providers
Google OAuth
- User clicks "Sign in with Google"
- OAuth flow with Google (consent screen, redirect)
- On first login: User document created in MongoDB via the MongoDB adapter
- JWT token issued with user ID, admin flag, and profile data
Credentials
- User enters email/username and password
authorize()callback finds user by email or username- Password verified with bcrypt
- If MFA is enabled,
mfaPending: trueis set on the JWT — user must verify before accessing protected routes
JWT Callback Pipeline
The jwt callback runs on every token refresh and handles:
- Initial sign-in: captures user data + MFA flags from the authorize result
- Session updates (
trigger === "update"): refreshes DB data and checks for MFA verification via Redis
Admin System
adminboolean on the User model (defaultfalse)- JWT callback reads
adminfrom DB and injects it into the token adminProceduretRPC middleware checks the flag on every admin request
Route Protection
- Edge middleware — enforces MFA challenge redirect for users with
mfaPending - Server components —
auth()+ redirect in layout files - tRPC — procedure-level middleware (
protectedProcedure,adminProcedure) - Client —
useSession()for conditional UI rendering
Content coming soon — add your video and detailed writeup here.