Full Stack Authentication With Next.JS | Next Auth | Nest.JS

preview_player
Показать описание
📖 You will learn these:
✅ Protecting APIs in Nest.JS from Scratch
✅ Generate JWT Access Token and Refresh Token in Backend
✅ Save and keep Backend JWT Access Token and Refresh Token in Next-Auth Session.
✅ Refresh Tokens automatically with Next-Auth in Server and client components.
✅ How To Use Next-auth callbacks



🗃️ GitHub Repos: (Don't Forget to give a ⭐ to them on GitHub)

📖Chapters:
0:00 intro
0:01:15 Create Nest.JS Project
0:03:04 Installing Config Module for Nest.JS
0:03:35 Creating User Model
0:04:44 Prisma Service
0:05:21 User Module
0:06:33 Create User Service
0:09:40 Hash Passwords
0:11:14 Auth Module
0:11:56 Sign Up API: User Register API
0:16:03 Login API
0:22:58 Generating JWT Access and Refresh Tokens
0:30:00 Create User Profile API
0:34:14 Protect APIs with JWT Guard
0:45:10 Refresh Token API
0:51:14 Next.JS Section
1:01:04 Access Next-Auth Session with useSession Hook
1:02:28 SignIn Button Component
1:06:26 Session Type Correction
1:08:44 Using Next-Auth Callbacks for Keeping Backend AccessTokens in Session
1:14:34 Signup Page
1:17:45 Dashboard Page
1:18:45 Access Next-Auth Session in Server Components with getServerSession()
1:20:43 User Profile Page
1:21:57 Include Access Tokens in Http Requests to Backend Server
1:24:07 Protect Dashboard Page from UnAuthenticated User with Next-Auth MiddleWare
1:25:45 Refresh Access Tokens Automatically with Next-Auth
Рекомендации по теме
Комментарии
Автор

A masterclass. Your video is the most complete on YouTube. Most of them always skip an important step, so their video become useless.
You've made everything from A to Z, thanks a thousand time 🙏

qunther
Автор

Not an easy transition to the NextJS section if you're following along with code, but if you can figure it out, hands down one of the best tutorials out there for refresh tokens for both client and server.

larrymcfarlane
Автор

I can assure you, this is one of the best explanations on implementing authentication in Nest/NextJs

tonyfrenzy
Автор

Hi, I have a question. The refresh token is only use when you reload the page or re-login. What's happen if the access token is expired then you call an API without reload the page? I'm so confused, please help me awnser this. Thank you!

angHoangAnhQuan-kbyq
Автор

Thanks for the great tutorial. I just want to make one clarification for those who are not familiar with JWT authorization. The refresh token must be implemented in such a way that it cannot be used more than once. And if an malicious user gets your refresh token and uses it, you will notice it immediately when you try to use it on your side. But in your implementation, if I understand correctly, the refresh token is reusable, since it is hardly possible to implement it without saving the token value itself to the database.

eugenetsymbal
Автор

Very good tutorial, perfect u said a lot of things can not find in others tutorials, especially how to refresh the accessToken silently.

hc
Автор

Hey thank you so much, you made this very clear to me, I'm using session and not JWT, but your content is currently helping me a ton to setup all this stuff ☺

vinception
Автор

I will also learn this Tutorial, The combination in this tutorial is awesome !
I see how amazing things NestJS can do !
I am still waiting for NestJS Postgres TypeORM, JWT Token, Key Cloak authentication, user role and OTP login !oo

PattySpicy
Автор

wow... this is the video I've been waiting for, thanks man

rahmatsulistio
Автор

Hey can you make a video with both google and oauth provider like google with capabilities of storing both of these in a database

sulavbaral
Автор

Thank you so much, NextJS Auth explained well with external BE... amazing

owaissurferaccount
Автор

In your components you have manually added the Bearer totken which is not a easily maintainable approach, what if refresh token in invalid?

ozdadev
Автор

good job bro ! A most comprehansive tutorial I've seen.

АлександрМерный-мч
Автор

In CreateUserProfile section you can also replace id with +id so it will convert the string to number

paintheworld
Автор

Hey ! Nice video!
I've just got one question: how do you ensure that, on the Next side, the user is automatically logged out when their token expires?

lucasdindault
Автор

Thanks alot for the amazing videio
but now what will happend if the refreshToken expired? How I can force the user to logout ? That the main issue i faced when i tried many times to implement the NextAuth.

noureddein
Автор

At 1:23:44 when you refresh it still has the username in the sessions (top right). How is a good way to have all of this updated as well when the accessToken expires?

eriksund
Автор

Amazing video tutorial. Everything explained and detailed to its core perfection!

dionisidoksani
Автор

When the session expires and the tokens refresh, if you don't press F5, it keeps calling the API thousands of times and when the Refresh expires it gives a lot of errors.

Valentim_Gab
Автор

Thanks a lot 🙏🏻🙏🏻
You have made it super clear.. and you managed to talk about i guess everything that related to authentication and authorization unlike other youtubers

tarek.k.hallak