Uploaded April 2024 | Updated November 2026, 2 hours ago
Learn authentication with Next-auth/Auth.js 5.0 for Next.js in this one tutorial. You will learn:
- How to set up Next-auth 5 in a Next.js project (auth.ts, middleware, Prisma)
- How to implement Google and GitHub login via OAuth2
- How to create email magic links with Resend
- How to add an admin role
- How to protect server components, client components (via useSession), server actions, and API route handlers
- The difference between server-side and client-side session retrieval
- The pros and cons of session vs JWT authentication
- How to achieve static caching on pages that contain auth
- How to make your Prisma client work on the Edge runtime (middleware)
- How to cache your session requests between server components
- How to update user data from the frontend
- And more
Project files:
Starting code: github.com/codinginflow/next-auth-v5/tree/0-Starting-Point
schema.prisma: github.com/codinginflow/next-auth-v5/blob/Final-Project/prisma/schema.prisma
β Get my full-stack Next.js with Express & TypeScript course: codinginflow.com/nextjs
β Get my free React Best Practices course: codinginflow.com/reactbestpractices
π Join my newsletter for regular web dev tips: codinginflow.com/newsletter
π¬ Join our developer community on Discord: codinginflow.com/discord
π£ Follow Coding in Flow on social media:
Twitter: twitter.com/codinginflow
Instagram: instagram.com/codinginflow
TikTok: tiktok.com/@codinginflow
Facebook: facebook.com/codinginflow
Timestamps:
0:00 - What we will cover
3:37 - Project setup + Vercel Postgres database
9:51 - Next-auth setup + Prisma adapter
25:53 - Google & GitHub login (OAuth2)
40:46 - Authentication in server components
55:31 - Protecting pages
1:00:35 - Authentication in server actions (& API route handlers), updating user data
1:05:09 - Admin role & TypeScript module augmentation (next-auth.d.ts)
1:13:51 - Deduplicating auth requests with React cache
1:17:23 - Client-side authentication (SessionProvider, useSession), vs Partial Prerendering
1:29:05 - Session callback (adding more data to user object)
1:34:56 - Email magic links (Resend)
1:40:36 - Deployment (Vercel)
Learn authentication with Next-auth/Auth.js 5.0 for Next.js in this one tutorial. You will learn:
- How to set up Next-auth 5 in a Next.js project (auth.ts, middleware, Prisma)
- How to implement Google and GitHub login via OAuth2
- How to create email magic links with Resend
- How to add an admin role
- How to protect server components, client components (via useSession), server actions, and API route handlers
- The difference between server-side and client-side session retrieval
- The pros and cons of session vs JWT authentication
- How to achieve static caching on pages that contain auth
- How to make your Prisma client work on the Edge runtime (middleware)
- How to cache your session requests between server components
- How to update user data from the frontend
- And more
Project files:
Starting code: github.com/codinginflow/next-auth-v5/tree/0-Starting-Point
schema.prisma: github.com/codinginflow/next-auth-v5/blob/Final-Project/prisma/schema.prisma
β Get my full-stack Next.js with Express & TypeScript course: codinginflow.com/nextjs
β Get my free React Best Practices course: codinginflow.com/reactbestpractices
π Join my newsletter for regular web dev tips: codinginflow.com/newsletter
π¬ Join our developer community on Discord: codinginflow.com/discord
π£ Follow Coding in Flow on social media:
Twitter: twitter.com/codinginflow
Instagram: instagram.com/codinginflow
TikTok: tiktok.com/@codinginflow
Facebook: facebook.com/codinginflow
Timestamps:
0:00 - What we will cover
3:37 - Project setup + Vercel Postgres database
9:51 - Next-auth setup + Prisma adapter
25:53 - Google & GitHub login (OAuth2)
40:46 - Authentication in server components
55:31 - Protecting pages
1:00:35 - Authentication in server actions (& API route handlers), updating user data
1:05:09 - Admin role & TypeScript module augmentation (next-auth.d.ts)
1:13:51 - Deduplicating auth requests with React cache
1:17:23 - Client-side authentication (SessionProvider, useSession), vs Partial Prerendering
1:29:05 - Session callback (adding more data to user object)
1:34:56 - Email magic links (Resend)
1:40:36 - Deployment (Vercel)










