Full Stack Authentication with Next-Auth and Next.js : All You Need to Know

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

КОМЕНТАРІ • 311

  • @p.durgashankar4464
    @p.durgashankar4464 Рік тому +3

    The best next auth tutorial we can find on youtube. The video has more content apart of only next-auth which is briliant in such a short video.

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

      Thanks🌷🌷 your really nice comment gives me energy to move forward.

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

    At the beginning I was really confused since the whole authentication thing is pretty advanced. But the more I watched the video, the more every previous step made sense to me. Thank you for this video, it helped me a lot!

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

      Thanks 😊 . I am really happy that it helps you ☺️

    • @GameDSS
      @GameDSS Рік тому +2

      @@SakuraDev btw do you think you can create a video about email confirmation after registration? Either with a link or a code?

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

      @@GameDSS Good idea, I will work on it.

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

      @@SakuraDev So my guess is that it's gonna include some form of jwt token being assigned to a user on account creation. So it might also me a good idea to include stuff like password change (forgot password or when logged in) and email change since im guessing they will use similar logic

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

    Probably the best tutorial about Next-Auth. Thank you for your work.

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

      Thanks. I am really glad you think so.

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

    I just realized your name is vahid
    دمت گرم وحید خیلی عالی بود

  • @kwasiezor1630
    @kwasiezor1630 Рік тому +2

    Honestly I've been looking for such a video. It's just an explicite and clean job. Thanks Bro. Keep it up 👏

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

      Thanks for your positive feedback. It really encourges me. Thanks 🌷🌷🌷

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

      @@SakuraDev yes it's a good job. I would like to know if you can add verification features to this tutorial, it can interesting especially for me. Thanks 👏

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

    Such a simple, clean and down-to-earth explanation! Great video, thanks man.

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

      I'm so happy to hear that you enjoyed the video! Thank you for your support and for taking the time to leave a comment. Your feedback is greatly appreciated and helps me to improve my content.🌷🌷🌷

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

      Its an awesome tutorial. Would you consider making one where the sign in component is customizable?

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

      @@somerandomchannel382 thanks for your nice feedback. have you seen "custom login page"?: ua-cam.com/video/hADeo48SATU/v-deo.html

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

    this is the only tutorial that worked for me, very good job, personally would add custom login/register to the tutorial as it is pretty desirable, still thanks for the tutorial

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

      Thanks 👍 I am working on the topics you mentioned

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

    Thank you for taking the time to share the knowledge. I have a firmer understanding of next-auth

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

      Glad you found it useful 🙏🌹

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

    I dont like on the videos and don't subscribe to channels just search for what I want but you deserve like and subscribe for making such a comprehensive video.

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

      Hi, your nice comment really gives me energy to move forward. Thanks for support🌷🌷🌷🌷

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

    This is the best tutorial about Authentication with Next-Auth and Next.js 13 for 100% sure, your explanation is so clean!
    Thanks a lot for your valuable knowledge!

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

    Dude, that is the best nextjs tutorial, thanks from Brazil

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

      Thanks for your nice feedback 🌹

  • @PJ-od9ev
    @PJ-od9ev Рік тому +1

    Amazing. Liked and subbed. I wish there was more explanation about callbacks in nextauth options.

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

      Hi welcome to my channel and in the upcoming videos I am going to explain more about the callbacks .

    • @PJ-od9ev
      @PJ-od9ev Рік тому

      @@SakuraDevThank you. I appreciate it.

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

    Hi, Very clear explanation ! Thanks! And waiting for Prisma tutorial ;)

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

      hi, thanks 🌷🌷. working on it

  • @UAng-ro9kt
    @UAng-ro9kt Рік тому +2

    Thanks for the video, it helps me a lot. A suggestion that jwt token verification would be put in middleware

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

      Thanks 🙏 and yes that'd be better.🌹

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

    thx i was searching for such inofmative and folder structured video in nextauth

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

    Thank you! This video helped me deal with Next Auth in Next 13... really good and to the point explanation.

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

      Thanks. Your nice feedback encourages me to move forward. 🙏🙏🌹

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

    Thank you so much. Just one question, why don't you use the Prisma adapter!? Thanks

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

      Hi, just wanted to show what is going on in low level.

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

      @@SakuraDev wow that's great ! Thanks again 🙏

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

      @@thebeep4427 Thanks 🌹👋

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

    I'm so glad that I found this amazing channel!

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

      Thank you so much for your kind words! I'm thrilled to hear that you find my channel to be amazing. 🌷🌷🌷🌷

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

    Awesome video! This is one of the most comprehensive videos I have seen on next-auth. One question I do have is about using the jwt. I understand that we can use jwt to protect the api routes. But instead of using jwt, can we simply use the session information? For example, I have an api route to delete a post, and i could get the session information from the getServerSession provided by next-auth and then get the current user id, and if this user id matches the user id of the post, then it will delete the post. If it doesn't match, then simply return an error. So I am just wondering if this would also be a viable approach to protect the api routes.
    Once again, great video and keep up the good work!

    • @SakuraDev
      @SakuraDev  Рік тому +2

      Hi, first of all, thanks for your nice feedback 🌹🙏🌹🌹. And about your question, yes you can use getServerSession to protect API. But with using JWT you can consume your API in other apps like mobile apps.

  • @LtTheXamax
    @LtTheXamax Рік тому +5

    Could you make a video about new server actions in nextjs 13.4?

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

    Sakura you definitely explained it in the best way possible. Thank you for the service! Like for the vid.

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

    You are such a great teacher. Thank you, sir. Please when you can please create a video on Prisma and what will be the advantages of using Prisma for Mongodb over using Mongoose. Thank you

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

      Thanks a lot for your nice feedback 😊😊🙏🌹. I will create a comparison video about Prisma and mongoose for mongoDB .

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

    Great series of videos. It helped me a lot. My one suggestion is if the data needs to be restricted to the JWT user_id then probably that should be extracted from the verified JWT and used in the primsa where clause. Otherwise a valid token could get the data from any user /api/user/1, /api/user/2, etc

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

    Thanks for great tutorial. More power to your channel. But I have a question, I saw that verifyJwt is used in the user/[id] route, is it possible to have like middleware to check or verify token? It seems like we will always put that code in every api endpoint's function?

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

      hi, thanks for your nice feedback🌷🌷, middleware will redirect to to login page if user is not authenticated, so it is not good. but you can use getserverSession if you don't want to use jwt.

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

    One of the helpful video ever I sea............... Thanks ❤❤❤❤

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

      Wow, Thanks for your nice word...🙏🙏🙏🙏🌹🌹🌹😃

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

    THANK U SO MUCH FOR THIS SIMPLE TUTORIAL
    i will subscribe you, have a nice day

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

    Thanks for the video :) Keep it up.

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

    Great easy to follow tutorial.

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

      Thanks for your nice comment.
      If you like this tutorial, please consider subscribing. 🌷🌷

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

    This tutorial is great and easy to understand. Thanks man!

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

      Thanks for your nice feedback. I am very happy it was helpful for you.🌷🌷

  • @sasha-rosca
    @sasha-rosca 2 місяці тому

    Great video. Just one note on the section about creating the login API... the function name should be "POST" not "Post".

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

      Oh, Thanks for bringing that to my attention, I will fix it in the repo

  • @Simon-yf7fo
    @Simon-yf7fo Рік тому +2

    Is there a reason for you to not add the Bearer prefix? I mean, it works without it but I don‘t think that‘s best practice because the token type could vary in complex systems. Besides that, awesome video. I‘d love to see how to revoke or invalidate a JWT since this is the hatdest step in my opinion.

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

      hi, no I just wanted to keep it simple but yeah the convention is that we should add Brearer prefix specially when we are using some libraries like Passport.js to do this job for us. By the way, thanks for your nice feedback 🌷

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

    Great video! Thank you for the tutorial.
    I encountered an issue during the build process of the app. I had to return a NextResponse.json(...) instead of a Response(...) from the POST. I assume this is related to the types that Next is expecting.
    I would really like to hear your opinion on the new App directory architecture, specifically regarding functions called on the server side. What are the pros and cons of calling a function directly in the server component versus creating a GET/POST and fetching from it?

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

      First thanks for your nice feedbacks. Well there is nothing wrong with calling feteching function directly on server components, but sometimes we need to fetch data in client components. in such use cases we can use APIs. Beside, With APIs we can feed other client apps such as mobile apps.

    • @cristovaoantunes3143
      @cristovaoantunes3143 Рік тому +2

      @@SakuraDev Makes sense! Thank you!

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

    Hello, I think using Prisma with SQLite is fantastic. However, I wonder if taking the same course with MongoDB would be beneficial? Thank you for considering my request.

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

      Yeah that would be nice, thanks for bringing that to my attention.

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

    Thank you this tutorial. Could you do a vid on how to handle pagination with prisma? Also how to implement it in the FE.

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

    Your videos are awesome. Can you do me a simple favor i created a program but no matter what i do getServerSession don't gives me empty objects even loged in or not. How can I solve that?

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

    You are a legend my friend, great video!

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

      Thanks for your very nice feedback 🌹.❤️🙏

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

    The best, some sneaky stuff but those were so clever.

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

      Thanks for your feedback 🌹🙏

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

    what a lifesaver tutorial. Thank you

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

      Thanks 🙏,I am glad it was helpful for you 🌹🌹

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

    Hello!! Excelent video!I'm having trouble typing the callback functions, how do you type the jwt and the session? just using any got me into trouble

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

    thanks you , your video help me on my deadline

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

      Really glad it was helpful for you 🌹🌹

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

    You are amazing!!!! You solve my problem that how to protect api. However, I would like to know how to serverside auth instead of client side. Did you cover it in your playlist? Thank you so much!!!!!

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

      Hi, Thanks 🙏. Do you mean auth in a sperate backend server?

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

      I mean using userServerSession.
      But I tried it. Thank you

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

    Hello big fan of you! I wanted to know how do you know this massive information by reading the documentation? or other? thankyou

    • @SakuraDev
      @SakuraDev  Рік тому +2

      Hi, I am really happy that my tutorial is useful for you.🌷🌷🌷. And about your question, its reading docs+research about the topic+github repo code examples+10 years of experience in coding. 🌷

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

    i didn't see yet the full video but thank you

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

    the documentation still discourages Credentials provider but it's the only one able to auth using your own backend auth, very common in business applications

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

      Yes, you are right. We can also turn other provider to username and pass . In my upcoming videos, I will talk about that.

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

    Good video thank you so much for this🎉, an alternative to return new Response is the NextResponse that already transform tha answer to json and includes all the needed headers for you :)

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

      Nice tip. Thanks for bringing that to my attention 👍

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

    Great tutorial!

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

    finally thank you for the tutorial sir, you very very help us to learn using jwt

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

    Simply sensational and very useful. Thanks!

  • @HaHoang-qk6ti
    @HaHoang-qk6ti Рік тому +1

    This tutorial is really a life saver. Thank you very much!

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

      Thanks 🙏.I am glad it was helpful for you 🌹

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

    Thank you for the great tutorial! For me, one question stands out, and that is how would you implement password resets? Obviously there would need to be an API endpoint and the reset logic is straightforward, but how would you go about safely getting the user to that endpoint using the tools in this video? A reset link would be ideal, but how do you create such a link that takes a user to an appropriately protected page? I'm really hoping to be able to do this for a client, but at the moment I think I am going to have to stick to the email provider and the google provider. Thanks again!

  • @FireTvAccount-o4r
    @FireTvAccount-o4r Рік тому +1

    Hi, i was thinking about a prisma crash course, i think it is a great db for developers...

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

      Hi, yes prisma is great and actually
      I have complete course for prisma: ua-cam.com/video/yW6HnMUAWNU/v-deo.html

  • @shawn-skull
    @shawn-skull Рік тому +1

    Wow this is awesome. I tried to do the same after watching your previous videos. I took me several hours and I thinks it has some bugs cause doesn't work as I would like💀
    I'm still struggling with uploading to Vercel. Please post videos about that.

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

      Thank you for your comment! We're glad you enjoyed the video. Uploading to Vercel can be challenging, but I will consider making a video about it soon.

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

    Hello, thank you very much for the great lecture.
    I'm not good at English, so I used Google Translate.
    Please understand if the translation is strange.
    Is the SessionProvider of next-auth a session obtained from the server?
    If I use jwt, I don't have to use session ?

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

      hi, I am glad it was helpful for you.
      session provider is not from server. it just react context that allows you ti access session throght application.
      and jwt is one of two way of keeping session of next auth.

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

      @@SakuraDev Thank you very much for your reply.
      Good lecture I really enjoy watching.
      Thanks to you, the program is more fun.
      thank you

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

      @@bongjames2222 🙏🙏🌹

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

    very well explained, thanks 🙏

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

    Hi your explaination is very clear and imp points are covered under it but its making bit confusion because you have uploaded separate videos for all authentication functionalities for nextjs. Why don't you make a complete single video which will contain all essential authentication and authorization methods such as next-auth, jwt api and client security using accessToken and refreshToken under it which will make us understand whole process in one go in single video. That will be really helpful as no content creator have uploaded video like this. Thank you!

    • @SakuraDev
      @SakuraDev  Рік тому +2

      well, I think thats a good idea. so I will go for it.

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

      @@SakuraDev Thanks for the reply. Please consider all points for proper prod level authentication and authorization for nextjs login registration and other data routes with next-auth and jwt tokens. Also please provide it with frontend connection.
      Thank you. Eagerly waiting for your this video.😇

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

      @@WM-fz5si ok .

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

    I encountered a problem when using signIn method with credentials, the result of that method always status: 200 even when I don't find any user data. If I tried it with postman directly to my server (I use express server), it will return 404 when no user found. I did tried to reject promise, return null and throw an error with try catch in next-auth.tsx. Any suggestion about this?

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

    Hi. I'm wondering why you did not use Prisma Adapter ? it supplies authentication and authorization based on role ! it's easier then.

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

      Mybe in next video 😁

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

      I just learned it's useful to link Google Provider (and cie) to our database, is it right ?

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

      @@mediacreatif Yes if you want to keep track of your users, you should do that.

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

      @@SakuraDev do you confirm that credentials provider is not concerned?

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

      @@mediacreatif I'm not sured i got your meaning, what do you mean by "not concerned"?

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

    Any reason you don't use get server session? That handles all the verification of jwt. Great video though!

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

      Hi, Thanks 🙏, we can use getServerSession as well. But using JWT has on advantage and it is when we have other clients e.g. a mobile app. With JWT we can authenticate mobile user as well. It kinda more generic.

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

      @@SakuraDev makes sense, thank you

  • @ヒマワリ-y4z
    @ヒマワリ-y4z Рік тому +1

    I really appreciate this nice video!
    For whom may get stack useSession() doesn't work in SigninButton function, which I got in my local,
    I had to use "status" as well.
    const { data: session, status } = useSession();
    if (status === "loading") {
    return (
    loading...
    )
    } else if (session && session.user) {
    return (...
    );
    }

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

      Thanks nice feedback, also thanks for your nice tip.

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

    Top! Thank you very much!

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

    nice video but i dont know if it is a correct question or not, if i go to the userpost do the headers automatically attach a token or do i need to copy and paste the access token to the postman? should be automatically attached whenever i go to any protected route. Can you please show a reference me how to do it?

  • @shawn-skull
    @shawn-skull Рік тому +1

    I did not understand why you used the access token to protect the api routes instead of getServerSession although I learned how to insert additional data to the User and modify the Session type

    • @SakuraDev
      @SakuraDev  Рік тому +2

      Hi, you can use both. But access tokens can be issued to different types of clients, including web applications, mobile apps, and other third-party services, allowing for a flexible and versatile authentication mechanism.

  • @aknozi2170
    @aknozi2170 Рік тому +2

    I can't access the password property for user @13:30. Is there any solution to that ? Or did i miss something ?

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

      we exclude the password from usee object.

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

    Pls make a video of upload this project to vercel.
    I used prisma and sqlite and having problem in vercel build but works well locally

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

      what kind of error you got?

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

      @@SakuraDev file not found. Location to database.
      If you make a video it will be very helpful
      BTW. Thanks for great content

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

      @@mohdsajidshaikh4291 oh, I am really sorry, I sent you another video.
      This is the right video 📷: ua-cam.com/video/khNwrFJ-Xqs/v-deo.html

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

    Well done, brother !! Tks a lot 🎉

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

    This tutorial is very usefull. But, how to revalidate user data when I refresh the page? When I delete user from database and refresh the page, the session still exists.
    Hopefully you can help me

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

      Hi. if your backend server is also on next.js you can call signout function from next-auth. but if your backend server is a sperate project, then you should set a low expiry time for jwt access token and then on refresh token API first you should check in your database if user existed or not. so if user is not existed (since you've delete the user) you send a 401 message as response of refresh token API to front end.

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

      @@SakuraDev thankyou bro

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

    Thanks for sharing! It runs all fine in dev mode.
    There's an issue when I build the application.
    I'm wondering if it's because we call api in another api and it's not workable in prod?
    npm run build
    npm run start
    After I created an account, and login it shows up error "fetch failed"
    connect ECONNREFUSED ::1:3000

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

    How to deploy this project on vercel and cpanel? Please make and upload project deploy video?

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

      I will make a video about it.

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

    Any thoughts on a forgot/reset password feature?

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

      Actually I am planning to create a vudeo about it very soon

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

    I haven't used nextauth in awhile but why did you create a new login api route and not just call prisma in the authorize function?

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

    Very useful. Thank you!

  • @AhmedSamy-fg5zz
    @AhmedSamy-fg5zz Рік тому

    When I provide the data and click sign in it returns the error page and when I check the network I find error unexpected end of json endpoint even though I did exactly what you did. Can you help me, please ? When I test the API in Postman it works right.

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

    Thank you very much !!! SIMPLY SUPER !!!

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

      Thsnks for your nice feedback.🌷

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

    nice job bro

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

    What are the difference between sessionprovider vs getserversession? I can still get session from getserversession

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

      Hi, getserversession is used in server components and api routes. in client components we can use session provider and useSession which is more straightforward

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

    I think you made a mistake, take a look from the official doc:
    "Previously, API Routes could have been used for use cases like handling form submissions. Route Handlers are likely not the solution for these uses cases. We will be recommending the use of mutations for this when ready."

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

      Hi, do you mean that we shouldn't use API routes to create Login end point ?

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

      @@SakuraDev The Login API its OK, because you are fetching data. But the User Register API part, following the docs, its not ok, because you are performing a mutation; you should use a Server Action instead.

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

    Very helpful bro

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

      Thanks for your nice feedback 🌹🌹🙏

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

    One doubt I had.
    Wrapping the whole app inside a session provider which is a client component, won't make whole application to be client side rendered? if yes. what's the solution for this?

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

      Nice question. The answer is No! You can have a Server Component wrapped inside Client component.

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

    can make video to use startigy of database and send token with cookies and check if exist in database

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

      Yes, This is exactly the topic of my next video

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

      @@SakuraDev Thanks a lot man
      if you can use an external api
      i have many problem with this approch cookies sendeed in next js but not saved in browser.
      if you can show as you external api in the new video

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

      @@ahmedakermi Hi, In this video, I have used an external API for keep track of users: ua-cam.com/video/cDWytA0V2kI/v-deo.html

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

    shouldn't we disconnect to prisma in the "api" folder methods after finishing the DB queries ?

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

      since we have one global instance of Prisma, we don't need to disconnect it. Welcome to my channel BTW 🌷

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

    How to implement register using next-auth . I did not see this in video.

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

      Hi, I will create a vid about it

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

    thanks, very nice and good video🤗

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

      Thanks 🙏, I am really glad you like it

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

    why not add api/user/path* to middleware? What's the point of having jwt guard here? It doesn't matter if it's 1 or 200 user route since they all should be protected equally

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

      Well, actually i wasn't complaining or criticizing you, i really want to understand, what was the reason? Have i missed something?

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

      Firstly, I wanted to show how you can create a JWT and validate it. Second, If you have a third app that consume your APIs, like a mobile App, You should protect your APIs with JWT.

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

    At 12:26 why can’t you just query from the database directly in the async authorize function?

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

      We can. But I wanted to show you what would happen if we had a separate backend.

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

    Thanks for your efforts but i noticed one thing , i don't know if it is a normal behavior : When clicking SignIn Button and entering the email ans password and clicking "Sign in with Credentials Button" the app rerenders the sign in button again then it render Immediately the Sign Out Button with the user name next to it,

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

      Solved it like that , because there is a status parameter whose loading state is causing the problem i mentioned:
      export default function Home() {
      const { data: session, status } = useSession();
      if (status === "loading") {
      //Or you can return null here
      return Loading;
      }
      if (status === "authenticated") {
      return (

      Signed in as {session.user.email}
      signOut()}>Sign Out

      );
      }
      return Sign in;
      }

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

    Do you know you can get the user session through a server side method ? Then you can wrap your layout with this server component : getServerSession ! Thanks to this, you can make directly Prisma request instead of fetching an API in the case of client side, like you did.

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

      Yes we can!

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

      @@SakuraDev it's an easier way ?

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

      @@mediacreatif well it depends, but the rule is as far as you can, send all processes to the server.

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

      @@SakuraDev that's why some say Next is becoming like PHP lol

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

    For some reason, following along and I'm getting a error 500 for my user api endpoint, even though, I have all the attritbutes in the prisma schema file. Although my login endpoint works fine and returns null so far when I put a "wrong" user info in. Any suggestions? Been struggling with it all day

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

      Hi, what is the error. 500 is internal server error, so you can find error message on vscode terminal.

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

      @@SakuraDev the same way you used your software for api endpoint testing I did with postman. But on VSCOde it was saying it was was an error with the bcrypt

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

      any suggestions? I still havent figured it out@@SakuraDev

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

      @@hunggarchristian well, have you set the key for bcrypt encryption in your .env file?

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

      @@SakuraDev no, I havent seen that in the tutorial yet. Which variable is it in the env file?

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

    Hi, I have some doubts about using next-auth, what if i want to have an external api? I dont see a way of making the authorization for that external api routes using the jwt generated in the client-server in a simple wa ,maybe sending the user and checking if exist in the db in a middleware in the node external server but i dont think is a good practice, is there any way of generating the jwt on the external api and refresh it and keep using next auth? I ask this bc in the future I dont know if i will have a mobile app, and leave all api responsabilities to next.js doesnt seem to be that good ?

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

      Hi, thanks for your nice question.
      In this video I have used an external API : ua-cam.com/video/fYObrr3jf0w/v-deo.html

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

      @@SakuraDev nice!!!! Am glad you are able of making content of it!

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

      @@jesustzinon Thanks🌹👍

  • @muhammadalifdanielbinmohdh3188

    Will this work for other database types like postsql?

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

      yes, why not?

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

      ​@@SakuraDevok thanks also it will be appreciated if you make a updated video using server action
      Also you got +1 subscribe

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

    hello thank you for this guide ! is there easy way how to send token in header via axios, or should i call in component useSession than get token and send it as header ? ..you showed it via postman but not in real call

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

      hi, you can do it automatically. you can use the approach I used in this video: ua-cam.com/video/RPl0r-Yl6pU/v-deo.html&lc=UgwO6GcXLkBpxPjl7et4AaABAg

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

    when authenticating using jwt and google authentication how can we tell whether its the same user?

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

      You should keep track of jwts in a database

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

      Can you make a video that handles complete auth process with different providers (email+ google) with next,prisma,supabase(postgre)/planetscale?@@SakuraDev

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

    Thanks, i cloned the repo by couldn't make it work, for some reason it doesn't call the authorize function in the configuration provider.

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

    is diferent if i not use typeScript, or i can follow the tutorial using Javascript?

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

      You can use it. Just skip the types and interfaces.

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

    Thanks. Do you know how to handle logout when the user close browser without press the logout button ?

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

      I use Azure provider

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

      Hi, use This:
      window.addEventListener("beforeunload", (ev) =>
      {
      signOut();
      });

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

    any chance you could do a video like this with Sanity?

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

      Hi, sure. It is on my list.

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

      @@SakuraDev thats great! the documentation from Sanity is really hard to follow.

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

      @@SakuraDev would I be able to contact you with some assistance on using the next-auth-sanity plugin? it seems easy to setup but I keep running into issues.

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

    Bro you are the best!

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

      Thank you so much for your kind words! I'm thrilled to hear that you enjoy my content and find it valuable. I appreciate your support and hope to continue creating content that you'll love. 🌷🌷🌷

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

    any chance to add all users to a mysql db?

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

      I'm not sure I got what you mean exaclly, but if wanna insert all users from an other source you can do it with a sql script

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

    Can we use phone number authentication with next auth?

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

      yes we can, but we need some sms service to send a verification message to users

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

    did you made a video to store the next session in database ? some users deactivate cookies in their navigator !

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

      we can do that with adapter. I recently created a video for saving session in supabase database.

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

      @@SakuraDev do you have the link pleaee ?

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

      @@mediacreatif
      this is the link 🌹
      ua-cam.com/video/ogrnOefwGnA/v-deo.html

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

    Hi, I have those error when I deploy to Vercel “"Type error: Route "app/api/auth/[...nextauth]/route.ts" does not match the required types of a Next.js Route." . Everything works fine locally but when deploy to vercel it cause this error during build time. Do u experience this? And to solve it? Thx 🙏

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

      build time error fixed but still give no secret error