Next Auth Credentials Provider - Ultimate Guide

Поділитися
Вставка
  • Опубліковано 5 вер 2024

КОМЕНТАРІ • 176

  • @edwinmuriithi9819
    @edwinmuriithi9819 8 місяців тому +4

    The clarity in your delivery and step-by-step guidance turned what was a struggle for me into a smooth learning experience.Cheers! 👏🚀

  • @arxci9402
    @arxci9402 11 місяців тому +15

    Im going to lose my mind hearing you say Prisma wrong

  • @patrickmbugua4942
    @patrickmbugua4942 9 місяців тому +1

    I really sort this type of content,prisma,custom login page ,credentials,next-auth so far this is the best tutorial for that

  • @tsykin
    @tsykin 6 місяців тому +2

    Best tutorial I have seen on credentials auth with NextAuth! Thank you so much for providing such valuable guidance, it was really easy to follow and understand 👍
    Instant sub

  • @user-gc5qm4er3b
    @user-gc5qm4er3b 10 місяців тому +1

    So cool. The tutorials in the Chinese community are so old that I had to come here for help

  • @codelery414
    @codelery414 Рік тому +6

    Brett keeps dropping the right tutorials at the time I need them. Good job sir

  • @AbhithShaji
    @AbhithShaji 4 місяці тому +1

    This is best next-auth video i've seen. Great work man.

  • @Code-prince
    @Code-prince Місяць тому

    You are a good teacher thanks. Even as i used next14 it still looked simple with no errors

  • @UsamaAnsari-j4i
    @UsamaAnsari-j4i 2 місяці тому

    Thanks a lot. Your explanation was very clear and concise 😊

  • @DagmarJS
    @DagmarJS 3 місяці тому

    Thank you a lot for the tutorial 💕 I was searching for a tutorial how to implement credentials in NextAuth and IMO this video is the best one I found

  • @SUSPICIOUSCABBAGE
    @SUSPICIOUSCABBAGE 9 місяців тому +1

    Thank you. The official next auth guide for credentials provider is broken and this helped out

  • @kenthefley2226
    @kenthefley2226 Рік тому +3

    Great tutorial, Brett. It would be really cool to learn how add to this so a user can reset their password.

  • @dios8256
    @dios8256 8 місяців тому +2

    1 big problem with this is that credentials provider auth is not persisted in the DB. So you can't use getServerSession in server components which are used frequently in later versions of next!

  • @spektree8448
    @spektree8448 10 місяців тому +1

    Bro is majestic

  • @aymendev1
    @aymendev1 Рік тому +6

    You did miss a part , if we look at the redirect method that you made after signIn , even if the user provide wronf credentials , it still route him to dashboard

  • @yanDev
    @yanDev Рік тому +1

    Thanks from France for this Tutorial!

  • @mounirben9370
    @mounirben9370 5 місяців тому +1

    THANKS FOR THIS GREAT TUTORIAL

  • @user-vl6hc6zs5b
    @user-vl6hc6zs5b 8 місяців тому +1

    Thanku sir this video very helpful for and my all concepts and doubts are clear.🥰🥰

  • @maxpayne9074
    @maxpayne9074 11 місяців тому +1

    I don't understand. How this example use adapter Prisma? Session won't be save in database. We can you next-auth without adapter Prisma, and in authorize () call Prisma.

  • @shivpratik
    @shivpratik 9 місяців тому +1

    Thank you for the detailed tutorial! Can you also make a video on "Remember Me" functionality with Next Auth?

  • @tecsmith_info
    @tecsmith_info 7 місяців тому +1

    16:11: You can also get a string from the cmd 'openssl rand -base64 32' 😄

  • @patite3103
    @patite3103 Рік тому +7

    Could you please provide the link to the Github repository for the code? thank you

    • @shanemur
      @shanemur 10 місяців тому

      Brett keeps deleting my comment so I'll keep writing it. If you're here in believe that this is a solid tutorial on Next auth, this ain't!!! Brett solution is utter rubbish!! I've recreated he's solution only to find zero authentication happening, users can access the dashboard page by localhost:300/dashboard WITHOUT NEVER logging in!!! users can login with any email or password without NEVER registering that user. He's solution is a complete joke. Don't waste your time here I like, there is ZERO authentication happening with he's tutorial!!!

  • @moteteletsa2034
    @moteteletsa2034 9 місяців тому +1

    Excellent video, and I was able to implement auth in my app just by watching this video. However, in my case, session object only has email address, and both name and image are undefined, but in your case, the name property has your name, and the only field that does not have a value is image.
    Here are my questions: Where are name, email and image properties defined for a session object? How do I fill then with information? (By the way, it took me to watch your video on callbacks to include that name, but I am just curious as to why it was not happening with me yet in your case the name property was being appropriately filled
    ). Thanks in advance.

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  9 місяців тому

      Thank you for checking out my content and to answer your question: it can be multiple reasons. If you are using the credential provider, make sure to check your register API endpoint and that you are successfully registering a user to your database. Then make sure your catch all route is correctly verifying the credentials on the sign in. I would recommend console logging values that are associated with your login to see which step isn't working correctly.

  • @eshw23
    @eshw23 Рік тому +7

    Nextjs CRUD with prisma and a database would be great, maybe a simple todo app?

  • @isSatoshiReal
    @isSatoshiReal Рік тому

    Very good, followed your tutorial and got everything working, subscribed.

    • @shanemur
      @shanemur 10 місяців тому

      Brett keeps deleting my comment so I'll keep writing it. If you're here in believe that this is a solid tutorial on Next auth, this ain't!!! Brett solution is utter rubbish!! I've recreated he's solution only to find zero authentication happening, users can access the dashboard page by localhost:300/dashboard WITHOUT NEVER logging in!!! users can login with any email or password without NEVER registering that user. He's solution is a complete joke. Don't waste your time here I like, there is ZERO authentication happening with he's tutorial!!!

  • @mateimarian2630
    @mateimarian2630 Рік тому

    Thanks it helped me a lot, when building my Saas.

  • @harsinghsekhon5935
    @harsinghsekhon5935 9 місяців тому +1

    Thank you so much Brett!

  • @snoopytoon2589
    @snoopytoon2589 Рік тому

    The Best Next-Auth tutorial on the internet

  • @axryuk
    @axryuk 8 місяців тому +1

    You cant use prisma adapter and jwt at the same time lol ,when using JWT you have pretty much no control over sessions after you give them out - you cant revoke the token on user deletion for example, You should have explained that

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  8 місяців тому

      maybe next video, you can sit me down and explain to me what details I should go over.

  • @olaleyeoyewunmi6978
    @olaleyeoyewunmi6978 Рік тому +1

    Really love your video… please can you make a video using typescript … I’m having issues passing the session as a props in the rootLayout

  • @romankostiuk
    @romankostiuk 7 місяців тому +1

    Minute 47, when you just wrapped body with Provider - it's not works. Not sure why for now. I esume because you didnt pass any props to provider and Session provider requires session as a prop but its possible onli in client component. That why I hate tutorials who are not using typescript. Anyways, actualy very good and detailed tutorial but still you shold try to use typescript for you work and for tutorials as well because a lot of bugges appire when you not use TS.

    • @romankostiuk
      @romankostiuk 7 місяців тому

      actualy, I was wrong as well, it was not working because due to you tutorial if there is no email or password you returning new NextResponse which is not correct. This function can return aither user object or null. authorize function is not correct place to handle errors in this case

  • @merakli2022
    @merakli2022 Рік тому +1

    Thank you for the great tutorial. Keep up the good work!

  • @oleksandrstepaniuk9491
    @oleksandrstepaniuk9491 Рік тому

    Дякую, саме те що шукав!

  • @xannylz
    @xannylz 6 місяців тому +1

    Thanks blud!!

  • @Nexjsdeveloper
    @Nexjsdeveloper 10 місяців тому +1

    tnx, great tutorial, my question is how bcrypt can unhash hashedPassword without any salt ? (how this working?)

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  10 місяців тому

      You would have to salt the password. And then use bcrypt package custom methods to unhash.

  • @techreview588
    @techreview588 6 місяців тому

    Awesome Tutorial! Can You Please Tell me Which Extension you used who gave you the recommended Code to write for the next line?

  • @mdamirhossain9376
    @mdamirhossain9376 Рік тому +1

    Awesome content. Just right things at the right time. Love it.

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  Рік тому

      Glad you enjoyed it!

    • @shanemur
      @shanemur 10 місяців тому

      Brett keeps deleting my comment so I'll keep writing it. If you're here in believe that this is a solid tutorial on Next auth, this ain't!!! Brett solution is utter rubbish!! I've recreated he's solution only to find zero authentication happening, users can access the dashboard page by localhost:300/dashboard WITHOUT NEVER logging in!!! users can login with any email or password without NEVER registering that user. He's solution is a complete joke. Don't waste your time here I like, there is ZERO authentication happening with he's tutorial!!!

  • @kmustafa0
    @kmustafa0 4 місяці тому +1

    Thanks a lot

  • @SamTipton
    @SamTipton 7 місяців тому

    It's odd that the User model does not contain a password field, but you pull it out in authorize no problem. I'm using mongodb adapter, there is no schema configuration provided in the docs and authorize is not happy with the user type I'm trying to return from authorize.

  • @Robert-jt9yg
    @Robert-jt9yg 10 місяців тому +1

    If I have a express.js backend where I have setup a MySQL database with Sequelize, and i have a next.js frontend, how could I make it work with NextAuth?

  • @jellyfish1772
    @jellyfish1772 9 місяців тому +2

    you should have used typescript

  • @gaopeng6573
    @gaopeng6573 8 місяців тому +1

    Thanks mate, that is great video! By the way, how could I test credentials signin or signup with postman? Thank you!

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  8 місяців тому

      You can use the endpoint for that catch all route and test it with that endpoint. You can test with a POST request for register and GET for login

  • @tolyan8161
    @tolyan8161 11 місяців тому +1

    git repo would be super-helpful with few nuances

  • @marcelinoborges5088
    @marcelinoborges5088 8 місяців тому

    Where is the setup for redirecting the user to the dashboard after successful login?

  • @sunilmaurya6594
    @sunilmaurya6594 8 місяців тому +1

    I did the same step but when im going to login it redirected to me "/api/auth/error"
    can anyone tell why this is happening?

  • @jatinduggal1975
    @jatinduggal1975 7 місяців тому +1

    you used dashboard page as client side, means all the protected routes will be client side ??? if yes, then whats the benefit of server side rendering in app router ?? please share the feedback

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  7 місяців тому +1

      You can have a client side page and still have it as a protected route. Client side is necessary for interactivity. Protected means that if the user isn't authenticated then they have no access to that route.

  • @SamTipton
    @SamTipton 7 місяців тому +1

    Is it strange to anyone else that an authentication library requires that you write your own password check logic? What am I missing here?? Why don't the docs start with a canonical example. I would imagine many projects are not going to want to go with only social logins.

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  7 місяців тому

      Actually Next Auth says they recommend not to using the credentials provider. So, they do not provide any password check logic out of the box.

    • @SamTipton
      @SamTipton 7 місяців тому

      @@brettwestwooddeveloper how innovative...

  • @amelianceskymusic
    @amelianceskymusic 10 місяців тому +1

    I've got an error, does anyone have any solutions?:
    PrismaClientInitializationError:
    Invalid `prisma.user.findUnique()` invocation:
    Error in connector: Error creating a database connection. (Kind: An error occurred during DNS resolution: proto error: io error: A socket operation was attempted to an unreachable network. (os error 10051), labels: {})

  • @shtse8
    @shtse8 6 місяців тому +1

    Are you hashing the password at server side? Shouldn't we hash at client side before sending the password to server to secure users?

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  6 місяців тому

      Password hashing client side offers no advantage against adversarial attackers. So, hashing it on the server is good enough!

  • @WM-fz5si
    @WM-fz5si Рік тому +2

    Nice video brett but also looking for all those actions including accessToken and refresh token for authorization.

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  Рік тому +1

      Yes I can do that as well. Felt video was long already

    • @WM-fz5si
      @WM-fz5si Рік тому +1

      @@brettwestwooddeveloper Yes Brett that will be really helpful 👍

    • @WM-fz5si
      @WM-fz5si Рік тому

      Hey Brett which screen recording software and which video editing software for you use for your videos?

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  Рік тому

      @@WM-fz5si obs studio for recording and premiere pro for editing

    • @WM-fz5si
      @WM-fz5si Рік тому

      @@brettwestwooddeveloper Thanks buddy 👍

  • @israelalfaro3621
    @israelalfaro3621 4 місяці тому

    the props session when you pass the value to the provider in layout.js?

  • @alvinjulian334
    @alvinjulian334 2 місяці тому +1

    I got an error 401 Credentials Sign in Not Supported, why is that??

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  2 місяці тому

      Could be multiple reasons but a 401 error code means that you are unauthorized to perform that certain action. Were you able to fix it since your comment?

  • @kludzidula1219
    @kludzidula1219 5 місяців тому

    I followed your steps but It didn't work maybe because of the versions what version of next js and auth did you use?

  • @MrCowch
    @MrCowch 11 місяців тому

    i followed your guide to a t and love it i dont really want to learn type script yet..... but i when i try to sign in i have to do it twice in order to get signed in.. did i miss something in this one or your other jwt video ? no errors just have to sign in twice.
    incase someone else runs across this i spent longer on this and found my issue was i was redirecting the same time i was signing in i put await in front of sign in and it solved my issue

  • @kavinselvaraj733
    @kavinselvaraj733 Рік тому +1

    really nice great and thanks, Keep Going

  • @warriorking778
    @warriorking778 Рік тому

    ! important
    How to implement role based redirect. eg. for user has "/user" and for admin has "/admin". When I signin successfully then it will automatically redirect.

  • @jonathanpodvin5727
    @jonathanpodvin5727 6 місяців тому

    Hey guys, is it possible to have in the first time a credential account and later connect with our google account with the same email than credential email ?

  • @thomasfrimpong6636
    @thomasfrimpong6636 Рік тому +1

    God bless you for this work. i expected logout any way.

  • @Sk8nRock
    @Sk8nRock 7 місяців тому

    Trying to implement this, but using a MySQL database. However it seems that next-auth doesn't support the database strategy and only works with JWT when using the credentials provider, so every time I login it tries to fetch the user session from the database, but the sessions table is always empty. If I remove the adapter altogether everything works, but I guess then there is no place to save the registered users...

  • @MnkyArtss
    @MnkyArtss 10 місяців тому +1

    Great tutorial but the zoom is kind of annoying

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  10 місяців тому

      Thanks for tuning in and I will take that into account. I had a feeling it might be

  • @golodiassaid4879
    @golodiassaid4879 10 місяців тому

    Great tutorial than you, but why username instead of email? How do you handle if you want email login and for example google and facebook? Thank you

    • @shanemur
      @shanemur 10 місяців тому

      Brett keeps deleting my comment so I'll keep writing it. If you're here in believe that this is a solid tutorial on Next auth, this ain't!!! Brett solution is utter rubbish!! I've recreated he's solution only to find zero authentication happening, users can access the dashboard page by localhost:300/dashboard WITHOUT NEVER logging in!!! users can login with any email or password without NEVER registering that user. He's solution is a complete joke. Don't waste your time here I like, there is ZERO authentication happening with he's tutorial!!!

  • @storyPlus12
    @storyPlus12 10 місяців тому +1

    why you didnt add the middleware?

  • @ojal_sharnagat
    @ojal_sharnagat 8 місяців тому

    How to do server side pagination by just fetching data from an API (without using MongoDB )?
    Please help! I'm stuck in the middle of a project.

  • @deepyslow
    @deepyslow Рік тому +1

    How is the registerUser function connected to the api route? The response variable hold the fetch info etc but its never used anywhere? Apart from console logging userInfo? Or am I missing something?

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  Рік тому +1

      register function send information to /api/route endpoint and this creates a user in the database. Then the catch all next auth route gets the user from the register by looking up the user in the database.

  • @AustrianTutorialHD
    @AustrianTutorialHD Рік тому +1

    and how do I give the users feedback for example if they want to login to their account but used the wrong password?

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  Рік тому

      I have the next auth ultimate guide which I go over how to use toast notifications. Skip to that time frame in that video. It has a red thumbnail on my channel

  • @aryaprima6626
    @aryaprima6626 Рік тому

    can i try this with sql?, this tutorial is very useful, and i am very happy, after few days studying about credentials

  • @gildsonalves6762
    @gildsonalves6762 11 місяців тому

    Hi, great job!
    Some questions...
    How about persist token to client and use it in API requests? How to refresh token too and use this solution with a google provider and still use a valid token to make requests, for example?

    • @ricardocastle6462
      @ricardocastle6462 11 місяців тому

      On Google Provider, you can write this code:
      authorization: {
      params: {
      prompt: "consent",
      access_type: "offline",
      response_type: "code",
      }
      }
      This will force the refresh token.

  • @tampantapipemalu6448
    @tampantapipemalu6448 8 місяців тому

    wow, thanks sir

  • @user-mn4zo4yl8u
    @user-mn4zo4yl8u Рік тому +1

    where are source code brother?

  • @shanemur
    @shanemur 10 місяців тому +1

    No Sign out functionality!!! therefore what is the point!

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  10 місяців тому

      you can just import signOut() from next-auth and then add it to an onClick.

  • @janpawedwa4590
    @janpawedwa4590 Рік тому +1

    You set the session as a required prop on the Provider, but when wrapping the body with it, you never pass that prop. How does that work?

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  Рік тому +1

      i don't know how it did but it did

    • @kosglu8705
      @kosglu8705 6 місяців тому

      @@brettwestwooddeveloper A quote from the documentation: "If you pass the session page prop to the - as in the example above - you can avoid checking the session twice on pages that support both server and client side rendering."

  • @user-rs2ym6sb9t
    @user-rs2ym6sb9t 11 місяців тому

    As `bcrypt` is not available on Edge runtime, how do I need to encrypt passwords?

  • @CodeHassanX
    @CodeHassanX 11 місяців тому +1

    Amazing

  • @Mike-ks7nr
    @Mike-ks7nr Рік тому +1

    This almost worked until I got to login. it doesn't print the session to the console or the dashboard.

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  Рік тому

      It should work, there must be something wrong in your code

    • @Mike-ks7nr
      @Mike-ks7nr Рік тому

      @@brettwestwooddeveloper I agree with you 100%, but I’ve watched so many tutorials and I’ve rewatched this video and your other videos and some others as well, but for some reason whenever I go to log in I run into a problem. If I go to “localhost:3000/api/auth/signin” and log in with valid credentials it always gives me an error at the top of the form. Can’t figure it out for the life of me but I’ll keep trying. I have to be messing up somewhere.

    • @Mike-ks7nr
      @Mike-ks7nr 11 місяців тому

      @kristielebaron-cz4fw no:( I watched a few other tutorials and kept getting the same problem. I tried following this one again from the beginning a few times to be sure I didn’t do something wrong but still had the same issue.

  • @snoopytoon2589
    @snoopytoon2589 Рік тому

    can someone help me with displaying the last login time along with the user-name when user's login

  • @mubashirwaheed474
    @mubashirwaheed474 11 місяців тому +1

    Hello Brett is it possible to redirect the user to the `onboarding` page after signup and the user doesn't have to login when using credential provider?

  • @sulavbaral9972
    @sulavbaral9972 Рік тому

    how shall we structure the database if we need both oauth and credential login

  • @arProject.webdev
    @arProject.webdev 11 місяців тому

    Quick question from newbie developer. At 46:45 when you marking 'use client' on Provider, and import it on root layout.js, is it the same as marking ALL child of this provider component (which is basically all of app pages) to be a client rendering? I can't wrap my head around this.

    • @jotaroisdarius1918
      @jotaroisdarius1918 11 місяців тому

      nope they don't all become client components

    • @pulpxi
      @pulpxi 7 місяців тому

      thanks for clarifing i was also wondering xD
      @@jotaroisdarius1918

  • @moodymshana6513
    @moodymshana6513 Місяць тому

    Where is the Id of that user and other important details of him

  • @phipattanachairinfong3503
    @phipattanachairinfong3503 Рік тому

    Where is the register code? Why can't I find it?

  • @nasarullahkhan3379
    @nasarullahkhan3379 Рік тому

    You already made the same video (The Ultimate Guide to Next Auth - Everything You Need).

  • @aymanechaaba
    @aymanechaaba Рік тому +1

    is it possible to implement this using server actions?

  • @lucasgonzalez8313
    @lucasgonzalez8313 Рік тому

    Hey ! can you help me with this error please? Type 'import("c:/Users/Lucas/Desktop/Nueva carpeta/login-app/node_modules/@auth/core/adapters").Adapter' is not assignable to type 'import("c:/Users/Lucas/Desktop/Nueva carpeta/login-app/node_modules/next-auth/adapters").Adapter'.
    Types of property 'createUser' are incompatible.
    Type '((user: Omit) => Awaitable) | undefined' is not assignable to type '(user: Omit) => Awaitable'.
    Type 'undefined' is not assignable to type '(user: Omit) => Awaitable'. In the code marks adapter an throw that error

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  Рік тому

      are you using typescript?

    • @lucasgonzalez8313
      @lucasgonzalez8313 Рік тому

      @@brettwestwooddeveloper yep, I'm using typescript. did I miss something?

    • @kylelogue9408
      @kylelogue9408 Рік тому

      You have to`import type { Adapter } from 'next-auth/adapters'` and then change your adapter line to `adapter: PrismaAdapter(prisma) as Adapter`

    • @kolegakrzys5190
      @kolegakrzys5190 Рік тому

      import { PrismaAdapter } from "@next-auth/prisma-adapter"; this should work fine

  • @tomryanxx
    @tomryanxx 2 місяці тому +1

    can't handle hearing "prism" instead of "prisma" ever few seconds arrrggh

  • @MoonMoon-qt7io
    @MoonMoon-qt7io Рік тому

    use ts ?🤔

  • @markuscwatson
    @markuscwatson 7 місяців тому +1

    prisma, not prism

  • @nasarullahkhan3379
    @nasarullahkhan3379 Рік тому

    Please add forgot password. Its essential part of login. I don't know why people ignore it.

  • @jonkerkoorts6265
    @jonkerkoorts6265 Рік тому

    Is it possible to share the github repo with us? 😃

  • @NatnaelAbebe-og8bt
    @NatnaelAbebe-og8bt Рік тому

    bro if I start learning web development to day is it worth or can I get a job please help me

    • @speedster784
      @speedster784 Рік тому

      It will take time to get a job

    • @kylelogue9408
      @kylelogue9408 Рік тому

      If you start today, you're already behind, but keep learning and you'll eventually get there. How motivated are you?

  • @armant11
    @armant11 7 місяців тому

    PRIS......MA!!!😂😂😂😂😂😂

  • @NOT_TON_Fan
    @NOT_TON_Fan Рік тому

    T3 STACK FULL COURSE

  • @speedster784
    @speedster784 Рік тому +1

    Bro you keep saying prism when its actually pris-ma. Great video though

  • @Gabriel-ue3jf
    @Gabriel-ue3jf Рік тому +1

    I tried to implement this but it doesn't create a session-token in the browser. It only works with the /api/auth/signIn default page but with /my-login it won't create that session. I even have pages: {
    signIn: '/my-login',
    },

    • @brettwestwooddeveloper
      @brettwestwooddeveloper  Рік тому

      Hi, can you show me the code so I can help you out

    • @Gabriel-ue3jf
      @Gabriel-ue3jf Рік тому

      @@brettwestwooddeveloper the problem strangely was caused by the name of the provider. Initially I named it name: "classic". After I changed it to name: "credential" and also added id: "credential", it started to work just fine. I don't have an explanation

  • @razac_zr
    @razac_zr Рік тому +1

    Nice video