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

Поделиться
HTML-код
  • Опубликовано: 15 янв 2025

Комментарии • 317

  • @hamzahahmad1670
    @hamzahahmad1670 Год назад +31

    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 RUclips, 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

  • @GuiKT88
    @GuiKT88 11 месяцев назад +2

    Hallelujah, thanks to let the people know what dependencies and versions you are using it, it helps so much man!

  • @Selimdede-jr2bv
    @Selimdede-jr2bv Год назад +2

    Hey dave when i started this job i used to watch your videos now i got my first job as a developer thanks man!

  • @Leesdjo
    @Leesdjo Год назад +9

    Thank you Dave. You have the heart to teach and help people who are trying their best to learn how to code .

  • @kenthefley2226
    @kenthefley2226 Год назад +35

    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.

  • @alexanderhenting
    @alexanderhenting Год назад +2

    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

  • @snivels
    @snivels Год назад

    The reason your videos are a cut above the rest is because you explain the 'why'. When you get an error you explain why you are getting the error and then you show how to fix it. When you paste a line of code, like the import of default from nextauth in the middleware file, you explain exactly what it's doing and also show how it works.
    Keep up the excellent work, you are appreciated!

  • @jior6
    @jior6 Год назад +1

    You make the best tutorials man, seriously thank you so much.

  • @Mayank_Bisht_MB
    @Mayank_Bisht_MB Год назад +19

    everyone who face middleware issue. first clear your cookie in console.

  • @andrewahlstrom8359
    @andrewahlstrom8359 8 месяцев назад

    Thank you Dave. I was having so much trouble trying to figure out how this was supposed to work. But after watching your video, the pattern became stupid simple. subscribed and looking forward to your content.

  • @ohiasdxfcghbljokasdjhnfvaw4ehr
    @ohiasdxfcghbljokasdjhnfvaw4ehr 3 месяца назад

    thank you so much for making this specifically with the new app router layout, i was very confused at first with the pages thing

  • @zilvinas5130
    @zilvinas5130 11 месяцев назад

    Damn, this tutorial is god tier comparing to other ones I found that tackle this topic. Detail all in the right places!

  • @joemathan6101
    @joemathan6101 Год назад +8

    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  Год назад +6

      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

  • @JasonRice-z7v
    @JasonRice-z7v 11 месяцев назад

    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.

  • @jordanryanethanowona2974
    @jordanryanethanowona2974 Год назад +1

    DAVE YOU ARE CLEARLY THE GOAT FOR ME. THANX A LOT

  • @gurditt_singh
    @gurditt_singh 9 месяцев назад

    This tutorial is so good! I was feeling so confused by next-auth and next.js, you made it seem so simple 😃

  • @RezHimself
    @RezHimself Год назад

    Another amazing toturial, to be honest I've been waiting for this video 👌👌👌

  • @nademkhan931
    @nademkhan931 Год назад

    A very nice nuanced explanaton of Next-Auth. Yes please, I would like to see follow on tutorials on role-based access as you mention at the end

  • @spiderwebbs02
    @spiderwebbs02 Год назад

    Your tutorials are the best Dave. I got a job because of you. I thoroughly improved my projects because of your tutorials.

  • @vishwanathsinha
    @vishwanathsinha Год назад +1

    Thank you Dave. This was very helpful. You made things crystal clear to understand and implement the next-auth with next 13.2 + version. Also when to use server and client component. Overall you made it very simple.

  • @DanielMolnar_Tuzla
    @DanielMolnar_Tuzla Год назад

    This is long awaited video. Thank you Dave, you helped me so much

  • @sahaneakanayaka3394
    @sahaneakanayaka3394 Год назад +1

    OMG! Thank you so much Dave ❤❤🙏🙏. Love your tutorials...

  • @samuelbigelow3480
    @samuelbigelow3480 Год назад +1

    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

  • @adimardev1550
    @adimardev1550 Год назад

    i love your voice Dave. keep up the Good Work! We Cant Thank You More Than We Say 🙏

  • @himanshutiwari9616
    @himanshutiwari9616 8 месяцев назад

    Very beautifully explained dave.
    love from India❤

  • @Evil_E_ye
    @Evil_E_ye Год назад

    I was making my website today and you uploaded this today saved many hours of work❤❤

  • @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! 💪😀)

  • @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! ruclips.net/video/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

  • @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 ❤

  • @YoshiGO71
    @YoshiGO71 7 месяцев назад

    Thank you Dave for your helpful content .

  • @knload
    @knload Год назад +2

    I'd love to see the role based user authorization video. Thanks for the video, nicely done. 👍

  • @kaputokalandanya5915
    @kaputokalandanya5915 Год назад

    I was literally just looking for this, thank you!

  • @AlirezaGarshasbi-kr1on
    @AlirezaGarshasbi-kr1on Год назад

    this tutorial is absolutely perfect.

  • @andrescampos8333
    @andrescampos8333 Год назад

    Phenomenal, best tutorial I've run across, thank you.

  • @abhijeetray9097
    @abhijeetray9097 Год назад

    Thanks Dave, it was really insightful

  • @GabrielMartinez-ez9ue
    @GabrielMartinez-ez9ue Год назад +2

    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.

  • @afsanazamannipa7711
    @afsanazamannipa7711 Год назад

    Elaborated Explanation. Great. Thanks

  • @k303k
    @k303k Год назад

    Thanks a lot for this tutorial Dave!

  • @owenhochwald506
    @owenhochwald506 10 месяцев назад

    Thanks you explained very clearly and now i understand!

  • @niallmoore8240
    @niallmoore8240 Год назад

    awesome work, thank you Dave!

  • @chan4est
    @chan4est 3 месяца назад

    This video was great. I was really confused trying to navigate the docs as they aren't updated to use Next.js 14. Thanks again!

  • @svitliarka
    @svitliarka 10 месяцев назад

    Great tutorial, thank you!

  • @karendoran3692
    @karendoran3692 Год назад

    Very beautifully explained as usual. I would love to see more next auth tutorials!

  • @Rikimkigsck
    @Rikimkigsck Год назад

    Thank you so much for explaining everything beautifully Dave.

  • @pablotexeira7579
    @pablotexeira7579 Год назад

    great job as always, thank you. you've been of great help once again!!!!

  • @fiendsgaming7589
    @fiendsgaming7589 Год назад

    Thank you Dave Gray! You're life saver!

  • @MangalaKarunarathne
    @MangalaKarunarathne Год назад

    I just completed short while ago... Nice tutorial with well explanation... Thanks a lot... 🥰

  • @jonathan_luz
    @jonathan_luz 11 месяцев назад

    The best content about this subject

  • @ashishsharma__
    @ashishsharma__ Год назад

    Thank you so much dave 😊

  • @rockNbrain
    @rockNbrain Год назад

    Great job Dave ... well explained , tks a lot 🎉

  • @fulltimefrontend
    @fulltimefrontend 7 месяцев назад

    This video was of great help, we are currently extrapolating to ditch Supabase auth for nextAuth

  • @maherworld1
    @maherworld1 Год назад

    Dude you are the best. much love

  • @replicant9611
    @replicant9611 Год назад

    Great tutorial, thank you!

  • @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!

  • @chandramani6682
    @chandramani6682 Год назад

    Nice job Dave 😊

  • @huutamnguyen2529
    @huutamnguyen2529 Год назад

    An easy tutorial to understand. Thank you so much!👍

  • @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.

  • @vittoriomorellini1939
    @vittoriomorellini1939 Год назад

    Great video and great explanation of Nextauth . Amazing tool to manage authentication. Thanks Dave

  • @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

  • @olagundoyeemmanuel
    @olagundoyeemmanuel Год назад

    Thank you so much Dave

  • @giannifed
    @giannifed Год назад

    Thank you Dave, amazing tutorial.

  • @onizuka_js1484
    @onizuka_js1484 Год назад

    Thank you for this amazing video! Super well explained, I just subscribed to your channel 🤩

  • @abdullahfurkanozbek7558
    @abdullahfurkanozbek7558 2 месяца назад

    fantastic tutorial, I just had one issue regarding api folder location, I did add it under pages rather than app folder which didnt work. I didnt understand why because in their docs it was built that way. Anyway after finding it everything went great. Thanks for preparing such a quality content. Db integration would be great in the future. Thank you so much

  • @sarowarhosen003
    @sarowarhosen003 Год назад

    Very informative lesson thank you sir

  • @desertpillar5286
    @desertpillar5286 Год назад +1

    Great stuff! This was the first tutorial that actually showed the basics of how to get it working and showed where the actual routes for the automatic pages lived. One thing I'm still a bit confused about is as why there's no default signup as well in Next-Auth as that seems to be an extremely common pattern. For any type of SaaS application, how would you relate the models to the correct user/org unless you have the user in your db? So showing a more advanced (but still basic) flow like signup => verify email => verified signed in, and signin => change password would be appreciated. Also perhaps how to make your own signin page call the right endpoints in nextauth. Thanks again for saving me a lot of time!

    • @desertpillar5286
      @desertpillar5286 Год назад

      I found the answer. It’s called Clerk. Use it and never look back!

  • @PENGGAO-fi5is
    @PENGGAO-fi5is Год назад

    Thank you Dave, nothing to say, brilliant.

  • @GeorgeDonnelly
    @GeorgeDonnelly Год назад

    This is an awesome tutorial, thank you!

  • @SAIDToufik-r4l
    @SAIDToufik-r4l Год назад +1

    Thanks for the content but what about editing the user informations on his profile page ? with that stack it's a pain

  • @adamjames8732
    @adamjames8732 Год назад +1

    There is an upcoming release of next-auth v5 which uses a universal auth() function and contains many breaking changes. I would love to see a renewed tutorial for the nearest v5 release. Keep on the good work..

    • @Rawdyn
      @Rawdyn Год назад

      Yep, this. Definitely this.

  • @XCodeWhisperer
    @XCodeWhisperer Год назад

    A very informative video. Thank you very much. Your code is perfect and very easy to read. And I would be glad to see more about role-based user authorization.

  • @alessandrosalzo8280
    @alessandrosalzo8280 7 месяцев назад +3

    For those having problems with the App Router and middleware, I moved the middleware file inside the app folder, and worked

    • @ΚωνσταντίνοςΠόρο
      @ΚωνσταντίνοςΠόρο 4 месяца назад +1

      If you're using App router without the src root folder you should move the middleware.ts in the root of the project at least that works in version 14.2 of next

  • @PySQLytics
    @PySQLytics Год назад

    Thank you Dave!

  • @sadeghmahboobifar7521
    @sadeghmahboobifar7521 Год назад

    YOU ARE GRATE DAVE, any time that I have any problems on coding , you will make a video about my problem, Thank you my friend

  • @tabdig
    @tabdig Год назад

    Very great video, helps a lot

  • @IndianCoders
    @IndianCoders Год назад

    Nice One Dave!!

  • @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!

  • @heguer87
    @heguer87 Год назад

    Once again. Thank you so much for your mater classes!! Your genius man. You know your stuff and know how to teach it! I will buy you a couple coffees lol

  • @vanhungnguyen7543
    @vanhungnguyen7543 Год назад

    Thank you so much to explaining

  • @AliAmeer
    @AliAmeer Год назад

    Lots of thanks to you ❤

  • @anay5233
    @anay5233 11 месяцев назад

    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

  • @ZaibGsm
    @ZaibGsm 6 месяцев назад

    good easy to understand.

  • @EricOnYouTube
    @EricOnYouTube Год назад

    Yes, role based auth would be fantastic. Thanks! :)

  • @khalilbenmeziane8836
    @khalilbenmeziane8836 Год назад

    Thank you Dave

  • @shayanhdry6224
    @shayanhdry6224 Год назад

    Hello Dave Yet another awesome Tutorial thank you , here instead of using session callback for getting picture you used getserversession ?

  • @neveriodev350
    @neveriodev350 Год назад

    Thanks Sir Dave!

  • @adejoh6650
    @adejoh6650 Год назад

    Thanks Dave❤!!

  • @zksumon847
    @zksumon847 Год назад +1

    Wow . Do you have plans to do one in clerk ?

  • @xuananhofficial7879
    @xuananhofficial7879 Год назад +1

    How to customize login button with Credentials?

  • @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.

  • @collinsk8754
    @collinsk8754 Год назад

    Excellent ! 👏👏

  • @frontend_ko
    @frontend_ko 10 месяцев назад

    very informative video giving a big laugh 36:06 🤣
    thanks~

  • @damiantriebl1747
    @damiantriebl1747 Год назад

    awesome!, good tutorial, the advanced playlist is coming soon???

  • @mahendranath2504
    @mahendranath2504 Год назад

    Thank you so much for the amazing content 👍👍🙌🙌👌👌😍😍

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Год назад

      You're welcome!

    • @mahendranath2504
      @mahendranath2504 Год назад

      @@DaveGrayTeachesCode I follow your channel and recommend you to my friends and family members to follow for a quality content

  • @Nanashi-rq7lk
    @Nanashi-rq7lk Год назад

    Useful tutorial for me

  • @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!

  • @HallucinAI
    @HallucinAI Год назад +1

    can you share the tutorial repo please? thank you

  • @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.

  • @brandonbailey4491
    @brandonbailey4491 Год назад

    Great vid. the challenge im facing is defining a pattern that allows me to integrate with a custom API. Any recommendations?

  • @codewithedraak
    @codewithedraak Год назад

    You are gem
    thanks

  • @vigenhovhannisian954
    @vigenhovhannisian954 Год назад

    Thanks a lot