Тёмный

Next-Auth Login Authentication Tutorial with Next.js App Directory 

Dave Gray
Подписаться 341 тыс.
Просмотров 257 тыс.
50% 1

Опубликовано:

 

27 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 314   
@hamzahahmad1670
@hamzahahmad1670 Год назад
It's a bit late to comment, but congratulations Dave on getting sponsors for your videos (this is the first one I've come across) There are plenty of amazing tutorial creators on RU-vid, but the amount of effort you put in your videos to explain each and every line of code, right down to mentioning the key binds you use, is just remarkable. Thank you for all your effort and I hope you gain even more success
@kenthefley2226
@kenthefley2226 Год назад
This is a very informative and useful video. It would be awesome if you could expand on this by connecting a database to store users along with a credentials signup. Users should also be able to reset their password. An explanation of that is hard to come by and something most of us will need.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Great suggestion!
@mohammadrizwan230
@mohammadrizwan230 Год назад
Please I have the same request, looking forward to the video 😊
@heguer87
@heguer87 Год назад
Same, with admin roles.
@safariambience4052
@safariambience4052 Год назад
This is a great suggestion. I have learned a lot from this great piece. Thank you Dave
@OnlyJavascript
@OnlyJavascript Год назад
Prisma ❤
@GuiKT88
@GuiKT88 8 месяцев назад
Hallelujah, thanks to let the people know what dependencies and versions you are using it, it helps so much man!
@Leesdjo
@Leesdjo Год назад
Thank you Dave. You have the heart to teach and help people who are trying their best to learn how to code .
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You're very welcome!
@samuelbigelow3480
@samuelbigelow3480 Год назад
This is super helpful, thank you! I do want to call out that you said you would never want to use a server component within a client component, but the application is doing that when you're talking about providers. The AuthProvider component is a client component and it the client/page.tsx component is a server component rendered inside of that
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You're welcome! I appreciate the call out because this shows I likely didn't explain myself clearly on this specific issue. "use client" creates a boundary between server and client components and all other components imported in the client component including children will be rendered as client components according to the Next.js docs: nextjs.org/docs/app/building-your-application/rendering/client-components ..so to follow this up, I searched the NextAuth docs for an exception with the SessionProvider used inside the AuthProvider we create in this tutorial. I did not find where those docs dive into how NextAuth works around this.. but if you add a console.log(user) to the UserCard component, build the project with npm build, and then run it with npm start, you will see that after logging in and visiting the home and server routes, the console.log shows on the server terminal - confirming they are still server components. If you visit the client route, the console.log will show in the browser console. Further, the build report after running npm build will also indicate those pages are SSR and not client components. I hope this helps clarify what I meant. This would actually make a good blog post / explainer topic - but the client component uses the useSession hook which uses the context. The server components instead use getServerSession which doesn't require the context. More clarification on using Context Providers with Server Components here: nextjs.org/docs/app/building-your-application/rendering/composition-patterns#using-context-providers
@Selimdede-jr2bv
@Selimdede-jr2bv Год назад
Hey dave when i started this job i used to watch your videos now i got my first job as a developer thanks man!
@Mayank_Bisht_MB
@Mayank_Bisht_MB 11 месяцев назад
everyone who face middleware issue. first clear your cookie in console.
@alexanderhenting
@alexanderhenting 10 месяцев назад
Hey Dave, after migrating from the pages router this tut helped me a lot on getting clear. There are a lot of tutorials out there and huge codebases with complex integrations and a lot of copy paste code, sometimes a bit hard to stay focused on the essentials. Greeting from Austria
@knload
@knload Год назад
I'd love to see the role based user authorization video. Thanks for the video, nicely done. 👍
@Den-yg4wz
@Den-yg4wz Год назад
Thanks Dave! It was very useful example, but very simple. 😉 Please, continue about NextAuth, cause you don't touch following themes: 1. Initial form for auth (how client can pass auth first time with credentials) 2. Working with DB, 3. How can clients change their credentials (email, pass, etc) at any time. 4. How can developer make own auth pages with another design? So we are waiting for next! Good luck, Dave! 💪😀)
@GabrielMartinez-ez9ue
@GabrielMartinez-ez9ue Год назад
Nice one...! One important point that maybe you can address in later videos is how to use user roles. To be able to pass roles to the session, you need to include them in the token, which is then read by the session.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
This is correct, and it is coming very soon!
@JasonRice-z7v
@JasonRice-z7v 7 месяцев назад
One of the best next-auth tutorials that actually covers the app router. Disappointing that the next-auth docs don't cover this and are instead using the older page router.
@jior6
@jior6 Год назад
You make the best tutorials man, seriously thank you so much.
@fulltimefrontend
@fulltimefrontend 4 месяца назад
This video was of great help, we are currently extrapolating to ditch Supabase auth for nextAuth
@Evil_E_ye
@Evil_E_ye Год назад
I was making my website today and you uploaded this today saved many hours of work❤❤
@jordanryanethanowona2974
@jordanryanethanowona2974 Год назад
DAVE YOU ARE CLEARLY THE GOAT FOR ME. THANX A LOT
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Thank you!
@anay5233
@anay5233 8 месяцев назад
Awesome tutorial I would be delighted if you could consider creating a tutorial on the process of authentication and authorization, encompassing both frontend and backend aspects. It would greatly enhance my understanding to learn about the complete flow, such as how the frontend transmits the authentication token to the backend during sign up or login. I'm eager to gain insights into the entire process. Frontend - Nextjs Backend - python
@SarahBrown-v6t
@SarahBrown-v6t Год назад
Hi Dave, this was an incredibly helpful video, I've now successfully set up Next Auth in my Next JS project with an AWS Cognito provider. Thanks for explaning everything so clearly and not glossing over the small details. I'll definitely check out your other videos on Next JS.
@anonihme5142
@anonihme5142 Год назад
if I may ask how did you find the cognito issuer? all the tutorials i've found for it used a cognito domain and amazon has revamped their whole UI making it really obnoxious
@anonihme5142
@anonihme5142 Год назад
nevermind, finally got there^^
@SarahBrown-v6t
@SarahBrown-v6t Год назад
​@@anonihme5142 sorry I didn't see your comment earlier, glad to see you got there! I followed this video to understand more about setting up the Cognito app client. I'd love to get Cognito working with the credentials provider as opposed to using their hosted UI, but that's on a future to-do list! ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-U4hEflgix9c.html
@anonihme5142
@anonihme5142 Год назад
@@SarahBrown-v6t cheers. Sadly the vid ends before he tries to log back in and sees that the next -auth logout function doesn't clear cookies on the cognito server, so the user is logged back in without being asked for his credentials, which is a major security risk. It amazes me that there's no simple way to do that. But then again, i'm a total noob, so simple for me is a very low bar. I shall persist and remain calm! thanks for the reply, best of luck
@SkippyTheCanadianKangaroo
@SkippyTheCanadianKangaroo Год назад
Thanks Dave for this video! It has actually helped me GET the right data for the Credentials login. But im having a little difficulty getting users to sign in with Username,Password. But with this video i was actually able to get a step forward! THANK YOU!
@judevector
@judevector Год назад
This is a very packed information and I really understand every bit of it ,I was in another tutorial before the guy was explaining it but it was very hard to get . Immediately I came here it just clicked ❤
@adimardev1550
@adimardev1550 Год назад
i love your voice Dave. keep up the Good Work! We Cant Thank You More Than We Say 🙏
@lan2media792
@lan2media792 2 месяца назад
Thank you Dave. This was very helpful
@PaarsahSoroury
@PaarsahSoroury Год назад
Thank you dear Dave, for always inspiring me to put my best foot forward, even when I don't feel like I belong. I hope the best for you in your life. Warm Regards.
@himanshutiwari9616
@himanshutiwari9616 4 месяца назад
Very beautifully explained dave. love from India❤
@mimos6198
@mimos6198 Год назад
Great explanation and unique content. I am waiting for more videos about Next.js, and problems faced by many beginners and solve these problems. Thank you for making this effort to explain the code
@markdenvermanuel8493
@markdenvermanuel8493 Год назад
Thank you much, Dave! I have been following and watching your Next series from the moment it was still in experimental phase and up to now that is already stable. Please create a video with signup that has a database and also the role based auth. Thank you and more power!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Role-based auth on the way. More to come!
@Reyescult
@Reyescult Год назад
Thank you, this has been very helpful. It would be great to have more coverage around OAUTH configuration (scope, userinfo, etc.) and sign-out from the identity provider. Anyway, thanks for the great content!
@kaputokalandanya5915
@kaputokalandanya5915 Год назад
I was literally just looking for this, thank you!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Glad I could help!
@karendoran3692
@karendoran3692 Год назад
Very beautifully explained as usual. I would love to see more next auth tutorials!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
More to come!
@MangalaKarunarathne
@MangalaKarunarathne Год назад
I just completed short while ago... Nice tutorial with well explanation... Thanks a lot... 🥰
@huutamnguyen2529
@huutamnguyen2529 11 месяцев назад
An easy tutorial to understand. Thank you so much!👍
@pablotexeira7579
@pablotexeira7579 Год назад
great job as always, thank you. you've been of great help once again!!!!
@libenhailu5193
@libenhailu5193 Год назад
Thanks Dave, Personally I need more authentication tutorials specially on next-auth it seems a little shady the code and the documentation also abstracts some details the only way to learn is is by experimenting it in my opinion, It would be amazing if you share us your findings.
@UwU-dx5hu
@UwU-dx5hu 10 месяцев назад
Yes.the docs are overwhelming
@zksumon847
@zksumon847 Год назад
Wow . Do you have plans to do one in clerk ?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
I can. Clerk provides some nice features.
@afsanazamannipa7711
@afsanazamannipa7711 9 месяцев назад
Elaborated Explanation. Great. Thanks
@siddiqahmed3274
@siddiqahmed3274 Год назад
That's a very comprehensive tutorial about next-auth. Thank you sir. and yes an advanced auth series (like react one) is very much appreciated. It is just a request to use sql based database this time for auth as we have covered mongodb in react.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Thank you!
@abhijeetray9097
@abhijeetray9097 Год назад
Thanks Dave, it was really insightful
@wasifalam545
@wasifalam545 Год назад
💡One tip for anyone who is just starting: Please analyze the starter code file first, on the timestamp 25:06 and then complete the rest of it By the way Great tutorial Dave 🔥Loved it.
@AlirezaGarshasbi-kr1on
@AlirezaGarshasbi-kr1on 9 месяцев назад
this tutorial is absolutely perfect.
@SalmanKhan-mn3cn
@SalmanKhan-mn3cn 2 месяца назад
Sir after configure the next-auth , you just directly go on UI without saying that how setup this ui login page therefore a lot of viewer leave the video
@nodesunlimited
@nodesunlimited 10 месяцев назад
thank you so much for all you do to enlighten me personally, please if you can expand this to include user roles, and how to redirect different users to their dashboard like if admin take them to admin only page on login and if only member take them only to member page ...
@DaveGrayTeachesCode
@DaveGrayTeachesCode 10 месяцев назад
I have another video about NextAuth and roles. The callback function is what you need to complete the routing you want.
@dailydestress6189
@dailydestress6189 Год назад
Please explain the concept using some flow diagrams for easy understanding. Simply copying along the code is not very practical.
@mikhacavin
@mikhacavin Год назад
hello, where i can watch the tutorial before this video ? so i can learn it before jump to this tutorial
@GeorgeDonnelly
@GeorgeDonnelly 11 месяцев назад
This is an awesome tutorial, thank you!
@abhishekbaksi330
@abhishekbaksi330 Год назад
dave , someday i will be like you and help the beginner's like i am now i am stuck in role based auth like admin , client , admin with add update delete and client only can acces or fetch the data and submit a form , and admin can toggle the status of the formdata it will be very helpful to make a video on the same thank you for being consistent and may god give you alot of happines to helping us as we are beginners
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Role-based user auth coming very soon!
@onizuka_js1484
@onizuka_js1484 Год назад
Thank you for this amazing video! Super well explained, I just subscribed to your channel 🤩
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Welcome!
@swahagaming5261
@swahagaming5261 10 месяцев назад
I have a question : Lets say I want to allow the user to choose what to use to login in with and then they can connect all there social media account such as twitter,instgram after they sign in . How do you do that ?
@PENGGAO-fi5is
@PENGGAO-fi5is Год назад
Thank you Dave, nothing to say, brilliant.
@Septumsempra8818
@Septumsempra8818 Год назад
How do we add production-grade auth if we're using a backend API like Django or Springboot? Suppose we wanna use an API that already has auth (either JWT or session-based) and all the password reset etc features built-in. How best do we set up auth and how best do we manage server state vs client state? Any resources or advice would be thoroughly appreciated.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Good questions - More to come on this.
@VijayMeena-z3u
@VijayMeena-z3u 11 месяцев назад
im facing an issue during production build. The middleware pages/middleware must export a middleware or a default function
@sarthakagarwal8521
@sarthakagarwal8521 Год назад
Hi Dave, is there any specific reason for using redirect instead of router.push?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Good question! 💯 A few reasons: 1) I think it is the accurate choice in this situation. 2) router.push comes from useRouter which is only available in client components. I can use the same redirect logic in both client and server components. 3) Redirect shouldn't impact your browser history. You want the callback to bring you back to where you were going after you login. I believe router.push adds the location to your browser history.
@sarthakagarwal8521
@sarthakagarwal8521 Год назад
@@DaveGrayTeachesCode Thanks for the reply Dave. I totally forgot that you cant you use hooks in server component. I had one more question. You mentioned that NextJS runs on serverless environment like AWS lambda. So going by this statement I can’t deploy a full stack NextJS app on, lets say, an EC2 instance?
@sferdev1
@sferdev1 Год назад
Hey Dave, Looking forward for a full-stack project with Next.js, typescript and MongoDB like Dandy shop project, please make one?
@IndianCoders
@IndianCoders Год назад
Nice One Dave!!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Thanks!
@svitliarka
@svitliarka 7 месяцев назад
Great tutorial, thank you!
@sarowarhosen003
@sarowarhosen003 11 месяцев назад
Very informative lesson thank you sir
@rsrinivas6025
@rsrinivas6025 10 месяцев назад
Hi dav i am trying to implement apple id sing-in in next js but i am unable to integrate the same, please make one video on the same. I am not find any reference as well please help me with this regards
@legendzain3273
@legendzain3273 Год назад
That's great, I have a question that if we have to design a custom form so with it we have to make post request to that dynamic route of next auth([...nextauth]) using fetch or similar api? or is there another way to send credentials to the api route? and how github or google provider can be placed in custom form, It would be a great favor for me if you make video on it or extend this video. Thanks. Hit like if you want this too
@megamind452
@megamind452 Год назад
Yes, please make a role based authentication video.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Coming soon!
@rakeshradhakrishnan271
@rakeshradhakrishnan271 Год назад
Can you please create a detailed tutorial video on NodeJs on LoopBack framework... Much Awaited... Lot of thanks in advance....
@Eva8621
@Eva8621 6 месяцев назад
Hi Dave, thanks for the really nice tutorial. I heard what you said about only using services on your channel that you think are really good. In relation to that, I was wondering what your opinion is on AWS Cognito? I am trying to do authentication using next-auth and Cognito but find this tricky. Any chance you would be willing to make a tutorial on this combination? Thanks again.
@HimanshuJoshi-jj2sv
@HimanshuJoshi-jj2sv 6 месяцев назад
Hey Dave Great Explaination but What if I want to add and get data to my database MongoDB
@codewithedraak
@codewithedraak 10 месяцев назад
You are gem thanks
@replicant9611
@replicant9611 Год назад
Great tutorial, thank you!
@sebmonti5904
@sebmonti5904 Год назад
I had to use middleware for internationalisation, how can I also use it for nextAuth. There is only one matcher
@PJ-od9ev
@PJ-od9ev Год назад
hi. when i open a new tab on the browser, it's like the session is gone and i have to login again even though i logged in earlier. i looked in the browser cookies and nextauth-session-token is not there for new tab.
@calebjoshuacj6883
@calebjoshuacj6883 Месяц назад
Hi , I wanted to deploy my application in some platform by using gitlab pipeline. So how to pick credentials because I cannot pass it directly in .env file... So how to pass the sensitive credentials like cognito id and all
@ZaibGsm
@ZaibGsm 3 месяца назад
good easy to understand.
@AliAmeer
@AliAmeer Год назад
it will be great if you can create tutorial about handle auth with backend with refresh token and handle roll protected route
@ashishsharma__
@ashishsharma__ Год назад
Thank you so much dave 😊
@Atrain1349
@Atrain1349 Год назад
Hey Dave, can you make an updated video of how to combine this implementation with firebase users? I want to use the credentials provider for email and password, but I want to be able to use the bult in sign in functions that firebase has.
@davidphan988
@davidphan988 Год назад
What about the navbar component?
@sahilatahar
@sahilatahar 4 месяца назад
Hey Mr Dave Gray, you have used types packages in dependencies not in devdependencies. Is this ok to have types packages in main dependencies? Anyone answer please?
@devippo
@devippo 11 месяцев назад
Hi Dave, Thanks for your tutorial. Looking for ways to implement a "Remember Me" feature by dynamically updating the maxAge. Have you been able to do this? I've seen some people destroy the token on browser close.
@wasd3108
@wasd3108 Год назад
dont nextjs docs tell u to prefer client side auth and use ss route guard only if you really need some data to not leak to the frontend that need to be protected?
@neveriodev350
@neveriodev350 Год назад
Thanks Sir Dave!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Welcome!
@pallavkumarpatra1767
@pallavkumarpatra1767 11 месяцев назад
hey @dave , I would like you to record a video on redux-toolkit + RTKQ + next-auth ,with refresh token and access token flow
@creativeartdesign4820
@creativeartdesign4820 Месяц назад
can you make a tutorial for authjs v5? it is in beta 20 now i want to use crediential and mongodb database.
@borooLIVE
@borooLIVE Год назад
Thank you BOSS! Great content!! Maybe tutorial about Prisma with Next?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Noted!
@jacoborode5167
@jacoborode5167 10 месяцев назад
How do I send an API request to protected route handlers?
@codewithedraak
@codewithedraak 10 месяцев назад
I have question Dave Can i use next auth for login when i am using Next 14 actions ? I made a form and give action to it and make login user , i am stuck at setting session what am i doing wrong please let me know
@tabdig
@tabdig Год назад
Very great video, helps a lot
@imoveri18chill
@imoveri18chill Год назад
Nice icon theme, which is it?
@codingpixel7660
@codingpixel7660 Год назад
Thank you Dave. can you please create one tutorial for how to secure nextjs Application and how to use statement management lib in next js 13 with server-side component
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Sounds like at least two tutorials 😀 thanks for the requests!
@collinsk8754
@collinsk8754 9 месяцев назад
Excellent ! 👏👏
@joshbleijenberg4000
@joshbleijenberg4000 4 месяца назад
great video!
@pellorocce4338
@pellorocce4338 11 месяцев назад
Thank you Dave nice tutorial and it is good that you mention your practice about client and server components, will work like you said because it made perfect sense to me, have a nice day!
@PySQLytics
@PySQLytics Год назад
Thank you Dave!
@joemathan6101
@joemathan6101 Год назад
Thanks Dave. Crystal clear step by step instructions on next auth. Now we have a deep understanding of how to configure and setup next auth in our projects. One suggestion a quick diagram of how the auth flow should be even more awesome!! Thank you for delivering quality content for us. Learning a lot from your videos.😊
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Thank you and good suggestion - while this default setup is very straightforward, I think some customized solutions may need further explanation in the future. The default setup uses a session cookie with an encrypted JWT (JWE). This is important because Next.js is hosted in a serverless deployment so the auth info is really in the JWE and is verified by a NextAuth server function (running in a serverless environment). Serverless is a confusing word. It means it is one big lambda function outsourced to AWS behind the scenes. The auth persists due to the cookie staying in the client. The serverless environment may go to sleep when inactive.
@nademkhan931
@nademkhan931 Год назад
Thank you for that explanation, indeed 'serverless' was confusing to me before reading this
@shan-4240
@shan-4240 7 месяцев назад
Hey, cant we send verify email using button? is there a way to do it?
@badhrikesavarajasm
@badhrikesavarajasm Год назад
After adding middleware.ts file it is not protecting my page
@Testingpp-x9z
@Testingpp-x9z 10 месяцев назад
can we give callBack url dynamically after signIn?
@AliAmeer
@AliAmeer Год назад
Lots of thanks to you ❤
@maxpayne9074
@maxpayne9074 Год назад
Hi Dave! Do you have tutorial, how use next-auth with Prisma (strategy: "database") ?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You could use this tutorial with any database. I show where you can request data from a database.
@HallucinAI
@HallucinAI Год назад
can you share the tutorial repo please? thank you
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
There is a link to it in the video description.
@khalilbenmeziane8836
@khalilbenmeziane8836 Год назад
Thank you Dave
@mhdfirassbarakat6587
@mhdfirassbarakat6587 4 месяца назад
when will you make a tutorial for next 14 ?
@ayesigwar
@ayesigwar 11 месяцев назад
Hey Dave. Thanks for the great tutorial. I see the majority of the nextauth code is in the /api folder and also on their site, they say it is built for serverless. Is there a way to adapt this to use an express server? Thanks
@noahginsburg6140
@noahginsburg6140 Год назад
Thanks so much. Any interest in diving deeper into auth flows with the PKCE flow?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Welcome! Always interested in learning more! 🚀
@АбеНиш
@АбеНиш Год назад
In what use cases should you use authenticated session in Client Component?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
With server components, I don't believe it is necessary if you want to avoid it. I will avoid it when possible. That said, it is possible in NextAuth and needed to be included as part of this tutorial.
@MrAtomUniverse
@MrAtomUniverse Год назад
Hi, i have API calls that are only for the user but the API provider is either NESTJS or Laravel API , which kind of token or auth should i use so the external API can deal with it?
Далее
Next-Auth on App Router - Solid Auth, Super Fast
17:20
Просмотров 115 тыс.
Avaz Oxun - Yangisidan bor
14:29
Просмотров 388 тыс.
Я ИДЕАЛЬНО ПОЮ
00:31
Просмотров 574 тыс.
Node.js Doesn’t Suck Anymore
16:59
Просмотров 112 тыс.
JavaScript for the Haters
2:50
Просмотров 1,5 млн
Master React JS in easy way
12:18
Просмотров 94 тыс.
Front-end web development is changing, quickly
3:43
Просмотров 1,1 млн