MENU

Fun & Interesting

🚀 Full-Stack Authentication with Next.js & NestJS in a Monorepo

Sakura Dev 30,215 lượt xem 6 months ago
Video Not Working? Fix It Now

Want to build a secure, scalable authentication system? In this tutorial, I’ll show you how to set up full-stack authentication using Next.js, NestJS, and Turborepo—perfect for SaaS applications, enterprise solutions, and modern web apps.

🔹 What You’ll Learn:
✅ Setting up Next.js & NestJS in a monorepo with Turborepo
✅ Implementing JWT authentication for secure user sessions
✅ Managing authentication in NestJS (backend) & consuming it in Next.js (frontend)
✅ Best practices for handling login, registration, and session management
✅ Enhancing security with hashed passwords, refresh tokens & role-based access control

📌 Why This Matters?
Authentication is a critical component of modern web apps. Whether you're building a SaaS platform, a cloud-based dashboard, or a business application, this tutorial will teach you the best security practices for user authentication.



💬 Got questions? Drop them in the comments!
🔔 Like & Subscribe for more full-stack development, Next.js, and NestJS tutorials! 🚀

How to split a monolith into microservices: https://youtu.be/MFQY4Qz7Ue8

Chapters
00:00:00 Intro
00:00:37 Topics
00:03:56 Creating Monorepo with TurboRepo
00:07:29 Prisma
00:13:32 Sign Up API In NestJS
00:20:10 Password Hashing
00:23:33 Sign Up Form In NextJS
00:27:42 Adding ShadCN UI in TurboRepo
00:31:06 useFormStatus in NextJS
00:34:03 Sign Up Server Action In NextJS
00:37:12 Form Validation With ZOD and useFormState
00:49:40 Login API In NestJS
00:53:34 PassportJS Local Strategy In NestJS
01:00:22 Local Auth Guard
01:03:22 Sign In Page In NextJS
01:05:56 Sign In Server Action
01:16:46 Creating The Session In NextJS
01:33:10 Creating The Dashboard And App Bar In NextJS
01:37:27 Sign Out In NextJS
01:40:06 Protecting The Pages In NextJS
01:44:48 Generating The JWT Access Token In NestJS
01:57:58 Protecting APIs with JWT Strategy In NestJS
02:10:18 Access Protected API From NextJS
02:15:54 Generating Refresh Token In NestJS
02:24:27 Refresh Token Strategy In NestJS
02:34:16 Refresh Token In NextJS
02:37:31 Session Update In NextJS
02:41:05 Auth Fetch: A Custom Auth Fetch Function In NextJS
02:54:42 Google OAuth 2.0 In NestJS
03:16:48 Calling Google Login API From NextJS
03:25:21 Invalidate Tokens
03:42:04 Global Authentication and Public Routes In NestJS
03:52:57 Role Based Access Control (Authorization) In NestJS
04:09:39 Role Based Access Control For NextJS Pages
04:15:18 Epilogue

⭐ Please Give a star to the repo if you use it.
GitHub Repo: https://github.com/vahid-nejad/NestJS-NextJS-Authentication-Turborepo

And If it is valuable for you, you can support me
Join https://www.youtube.com/channel/UCTKSxERKbrpQOTa7QjDPjZg/join

Comment