Auth.js V5 From Scratch

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024

ความคิดเห็น • 124

  • @plotitsyn
    @plotitsyn 6 หลายเดือนก่อน +9

    Another great video on Auth.js authentication.
    Looking forward to the full course: Next.js | PostgreSQL | Auth.js (Credential | Google | Apple | with role-based authentication), maybe even with the implementation of a user management page with the ability to change roles for each user (guest-user-admin) and a personal user account with the ability to change personal data.
    And, of course, thank you and good luck!

  • @yash-uy5ym
    @yash-uy5ym หลายเดือนก่อน

    You're a life saver, I was trying to figure out how to access auth user details in client components from the last 3 days. You explained this in 3 minutes
    ❤❤❤

    • @SakuraDev
      @SakuraDev  หลายเดือนก่อน

      Thanks! I'm so glad to hear that the explanation helped you! It's great to know it saved you time and effort.

  • @AbhishekPandey-ty5jf
    @AbhishekPandey-ty5jf 6 หลายเดือนก่อน +7

    The timing can't be more perfect.

  • @StanOgn
    @StanOgn 6 หลายเดือนก่อน +1

    Everything you need to know about Auth.js v5! Thank you!

    • @SakuraDev
      @SakuraDev  6 หลายเดือนก่อน

      Glad you like it 😊

  • @NilsFS7
    @NilsFS7 2 หลายเดือนก่อน

    I didn't find any info how to access the session from client components when using app router. Not even in the authjs docs... So glad I found this video! Thank you so much!

    • @SakuraDev
      @SakuraDev  2 หลายเดือนก่อน +1

      Really glad that it was helpful for you 🙂

  • @ShuaibShahzan
    @ShuaibShahzan 4 หลายเดือนก่อน

    Explained in a easily understandable language, especially for newbie like me, thank you so much. May god bless you!

    • @SakuraDev
      @SakuraDev  4 หลายเดือนก่อน

      So happy to hear that! Thank you so much

  • @paul8683
    @paul8683 6 หลายเดือนก่อน +1

    Great tutorial again! Recommended your video to a few people. No other channel makes it so easy to follow and helps get the basics in place so I can focus on my project instead of the changes to next-auth.

    • @SakuraDev
      @SakuraDev  6 หลายเดือนก่อน

      Thanks 🙏🙏🙏

  • @antonrybakou
    @antonrybakou 5 หลายเดือนก่อน

    Hi, thank you very much! Great work! Waiting for the next video "Next-auth v5 with Refresh token rotation" ))))

  • @lloyd1791
    @lloyd1791 6 หลายเดือนก่อน +8

    can you make the credentials provider role based?

  • @aaronanama9414
    @aaronanama9414 5 หลายเดือนก่อน

    Thank you for your videos. I really like the way you the concepts into chapters and explain them in a beginner friendly way. Please can you do a video on typescript and next typescript

  • @YondeCode
    @YondeCode 3 หลายเดือนก่อน

    Love you mate ! Thank you for this

    • @SakuraDev
      @SakuraDev  3 หลายเดือนก่อน

      Thanks you so much 🙏

  • @AlexStraight-zk1ig
    @AlexStraight-zk1ig 5 หลายเดือนก่อน +1

    Awesome content man.
    What theme are you using here?

  • @collinsk8754
    @collinsk8754 5 หลายเดือนก่อน

    Great tutorial! Clear and easy to follow! 👏👏

    • @SakuraDev
      @SakuraDev  5 หลายเดือนก่อน

      Thanks a lot 🙏🙏🙏🙏

  • @yaqubadesola1839
    @yaqubadesola1839 5 หลายเดือนก่อน

    You are indeed a lifesaver, More grease to your elbow bro

    • @SakuraDev
      @SakuraDev  5 หลายเดือนก่อน

      Thank you so much. Really glad it was helpful for you 🙂

  • @webdeveloper2795
    @webdeveloper2795 5 หลายเดือนก่อน

    Really great video, bro require jWT access token and refresh token with Next Auth 5, please use express js as backend as in previous video

  • @Amyzheng-sc3ej
    @Amyzheng-sc3ej 5 หลายเดือนก่อน +1

    Thank you for the video!! But May I know why I add the AUTH_SECRET with random string,it still shows Server error
    There is a problem with the server configuration.
    Check the server logs for more information.

  • @debanjanghosal618
    @debanjanghosal618 หลายเดือนก่อน

    24:07 I have only 1 doubt. When I am entering a wrong username or passowrd instead of showing the proper error message, it says "Server error
    There is a problem with the server configuration.
    Check the server logs for more information.'

  • @MusavirPasha-nh3ku
    @MusavirPasha-nh3ku 6 หลายเดือนก่อน +1

    if i run the source code..im able to navigate to middleware protected page...can you please tell me why?

    • @SakuraDev
      @SakuraDev  6 หลายเดือนก่อน

      I will fix that bug and push it on GitHub again. Thanks for bringing that to my attention 🙏

    • @erikgalajdask
      @erikgalajdask 5 หลายเดือนก่อน

      would be cool if u could share the fix, thx for the great vid@@SakuraDev

    • @sumonhossain889
      @sumonhossain889 4 หลายเดือนก่อน

      @@SakuraDev still problem, I cloned your code though.

  • @sujiths6588
    @sujiths6588 6 หลายเดือนก่อน +1

    Hi, I have cloned your repo, but when I ran it the middleware is not working like in the video. Even if the user is signed out the user is able to see the middleware page.

    • @jcen1918
      @jcen1918 5 หลายเดือนก่อน

      Exact same issue!

    • @adityaiiitr
      @adityaiiitr 5 หลายเดือนก่อน

      Anyone found the solution?

  • @MilindMishra
    @MilindMishra 6 หลายเดือนก่อน +2

    For some reason the middleware protection fails for my app, not sure why I did follow up with the docs but hard luck.
    Btw, great work on the video thanks!

    • @SakuraDev
      @SakuraDev  6 หลายเดือนก่อน +1

      Glad I could help

    • @MilindMishra
      @MilindMishra 6 หลายเดือนก่อน

      ​@@SakuraDev The middleware protected page isnt really protected, tried using your repository same results.

    • @MilindMishra
      @MilindMishra 6 หลายเดือนก่อน +2

      @@SakuraDev looks like we need to keep the middleware.ts file in the same level as the app directory if inside src when applicable, that fixed it.

    • @fiimble
      @fiimble 6 หลายเดือนก่อน

      Same here. The middlewareProtected page is always accessible.

    • @finenode8363
      @finenode8363 6 หลายเดือนก่อน +1

      @@MilindMishra thank you! your answer solved my issue.

  • @KrisKristiansen
    @KrisKristiansen 5 หลายเดือนก่อน +1

    Please show us how to create a custom credentials provider signIn form

    • @SakuraDev
      @SakuraDev  5 หลายเดือนก่อน

      I Will

  • @poizonncs8264
    @poizonncs8264 6 หลายเดือนก่อน

    Was eagerly waited for AuthJS5 video

  • @MilindMishra
    @MilindMishra 6 หลายเดือนก่อน +2

    If possible do add your github code repository for the same, thanks

    • @SakuraDev
      @SakuraDev  6 หลายเดือนก่อน +1

      Hey! Added

    • @aryan.prince
      @aryan.prince 6 หลายเดือนก่อน +1

      ayo no way milind spotted in the wild 👀

  • @sumonhossain889
    @sumonhossain889 4 หลายเดือนก่อน

    Everything you need to know about Auth.js v5! Thank you! But middleware protected not working , could you say?

  • @hktang13
    @hktang13 4 หลายเดือนก่อน

    Thank you. Great video!

    • @SakuraDev
      @SakuraDev  4 หลายเดือนก่อน

      Thanks 🙏🙏🙏

  • @neliobila
    @neliobila 4 หลายเดือนก่อน

    This video is wonederfull, thnx a lot

    • @SakuraDev
      @SakuraDev  4 หลายเดือนก่อน

      So nice of you

  • @user-kd7ld4ff4t
    @user-kd7ld4ff4t 6 หลายเดือนก่อน

    best explanation!!

    • @SakuraDev
      @SakuraDev  6 หลายเดือนก่อน

      Thanks 🙏🙏

  • @darkecnelis
    @darkecnelis 5 หลายเดือนก่อน

    Hi, this is a good guide, but i have a little probleme i want to change the scope like "providers: [discord(auth... { params: {scope: ["my scope"] }}), credentialsConfig]" but hes doesn't work

  • @lemondigitaldesign
    @lemondigitaldesign 5 หลายเดือนก่อน

    Thanks for the great tutorial, helped me to understand v5 better :)
    Quick question in case you may have an idea:
    authorized({ request, auth }) -- the auth always comes back as null in auth.ts and in the middleware if I import it and log out the session, even though I have a session in my server and client component. I clearly log in and out and session comes back with null or session details in my components and pages. But in auth.ts the ""authorized" callback it always returns as null and in the middleware the session also returns null ... any ideas while I google this? :)
    P.S.: I cloned your repo and realised that in your case the callback actually does nothing, it's as if it wasn't there ... very odd.
    P.P.S For anyoen else cloning the repo: the middleware file is in the wrong place. It needs to be in your project root (or in "src") at the same level as your app/pages folder but nt inside the app folder. Then the middelware works and then it also invokes the callback correctly.

  • @darawan_omar
    @darawan_omar 5 หลายเดือนก่อน

    How we can do that when use login in and when he want to visit another page that not access it and logout the use l mean signout and clear the ssesion

  • @jocow2
    @jocow2 4 หลายเดือนก่อน

    Great tutorial. Saved me a lot.
    I do see an issue however with retrieving the client session by using useSession in 1 specific usecase: refreshing the browser with F5 on the clientPage when you are logged id:
    useSession returns undefined.
    @Sakura Dev is this something where you can help with ?

    • @SakuraDev
      @SakuraDev  4 หลายเดือนก่อน

      Hey, useSession returns undefined immediately after refreshing the page but it will return the session quickly after a few seconds.

    • @jocow2
      @jocow2 4 หลายเดือนก่อน

      @@SakuraDev Thank you.
      How can I handle this functionally, because the 'undefined' comes into a if/then clause where we show some behaviour which we normally use for unauthenticated person (like showing a login screen).
      How should we solve that ?

  • @milinddhamu
    @milinddhamu 6 หลายเดือนก่อน

    How middleware directly redirected to sign in page if unauthorized users is accessing protected page

  • @KubaSobecki
    @KubaSobecki 6 หลายเดือนก่อน

    Great vid. Thanks!

    • @SakuraDev
      @SakuraDev  6 หลายเดือนก่อน

      Thanks 🙏. I'm really glad that you liked it 😊

  • @MrCuteguylol
    @MrCuteguylol 5 หลายเดือนก่อน

    AMAZING video! Thank you so much! A question though. Im using nest ts on the backend and im getting tokens. Can you guide me how to use tokens for authentication in next auth?

    • @SakuraDev
      @SakuraDev  5 หลายเดือนก่อน +1

      Thanks, You should keep the tokens inside the Auth session and whenever you want to call a backend API you should put the tokens inside the header of your request to backend API

  • @HigherStudyAspirant
    @HigherStudyAspirant 6 หลายเดือนก่อน

    thanks. please make a video on next js caching.

  • @mDHARYL
    @mDHARYL 3 หลายเดือนก่อน

    short video but great video
    thanks

    • @SakuraDev
      @SakuraDev  3 หลายเดือนก่อน

      Glad you liked it!

  • @ahmedkhabar
    @ahmedkhabar 4 หลายเดือนก่อน

    Hi, thanks a lot for this great content, I don't know if you notice that when you sign In with incorrect credentials there is an error on the server console, any solution for this ?

  • @mrfirstname578
    @mrfirstname578 6 หลายเดือนก่อน

    can you make example @auth/express access token refresh token and next js

  • @KrisKristiansen
    @KrisKristiansen 5 หลายเดือนก่อน

    Please show us how to create a custom signIn form using version 5.

    • @SakuraDev
      @SakuraDev  5 หลายเดือนก่อน

      I will do that soon

  • @johnaroj
    @johnaroj 5 หลายเดือนก่อน

    great video!!
    Can I write that same logic (callbacks:{authorized({request,auth)}) inside the middleware.ts?
    so checking the request.nextUrl.pathname to be middlewareProtectedPage and then redirect them to the login page

    • @SakuraDev
      @SakuraDev  5 หลายเดือนก่อน

      I haven't tried that, But I think It will do the job.

  • @haiduy5141
    @haiduy5141 4 หลายเดือนก่อน

    How can I implement AuthJS with next-intl

  • @exerge9202
    @exerge9202 6 หลายเดือนก่อน

    Hi, can you do a video on passwordless with nodemailer (sendgrid or any api is fine)
    im using prisma and postgres hosted on neon and im having issues, i get the email, but cant sign in, im struggling to solve the issue and auth.js docs are still not completed

  • @ojomudamola6674
    @ojomudamola6674 2 หลายเดือนก่อน

    Custom error messages from auth.ts to client components login page

    • @SakuraDev
      @SakuraDev  2 หลายเดือนก่อน

      Will be covered in next update

  • @eduardoserrano4150
    @eduardoserrano4150 6 หลายเดือนก่อน

    Great video thanks for uploading!!
    How can we overwrite the type for the session? i have tried creating a next-auth.d.ts file with its new type, I get the new correct types in vscode, but it will not accept any of the fields i am passing it and session is always {}

    • @SakuraDev
      @SakuraDev  6 หลายเดือนก่อน

      Hi thanks. You should use auth callbacks as well as the editing types in nextauth.d.ts file

  • @kemmouneismail3087
    @kemmouneismail3087 4 หลายเดือนก่อน

    for the credentials method, I'm working with external backend, should I send a post request inside the authorize function with the credentials in the request body, then await for the response then return the user object?

    • @SakuraDev
      @SakuraDev  4 หลายเดือนก่อน

      Yes, This is exactly what you need to do. Thanks for the visit BTW 🙏

    • @kemmouneismail3087
      @kemmouneismail3087 4 หลายเดือนก่อน

      @@SakuraDev thank you so much for answering me that fast, I still have 1 question, since I'll send the post request from that authorize function, how can I handle the loading state to make a loader or to disable the inputs, should I just set up a global state, or there is a better way?

    • @SakuraDev
      @SakuraDev  4 หลายเดือนก่อน

      @@kemmouneismail3087 well, you can set the loading state of sign in form with just a simple state. note that you don't call the authorize func directly from you sign in form. instead, you call the sign in function of the next-auth. this func then calls the autorize func. so you can just handle the loading state in the sign in form. just set the loading state to true before calling the signIn func and set it back to false just after that.

    • @kemmouneismail3087
      @kemmouneismail3087 4 หลายเดือนก่อน

      @@SakuraDev thank you so much sir, was very helpful

    • @SakuraDev
      @SakuraDev  4 หลายเดือนก่อน

      @@kemmouneismail3087 My Pleasure

  • @alooff
    @alooff 2 หลายเดือนก่อน +1

    Sir can you please provide theme name

    • @SakuraDev
      @SakuraDev  2 หลายเดือนก่อน +1

      Hi, It is bearded theme

  • @en_kratia
    @en_kratia 6 หลายเดือนก่อน

    Thank you

    • @SakuraDev
      @SakuraDev  6 หลายเดือนก่อน

      Thanks 😊

  • @PattyBeautCode
    @PattyBeautCode 6 หลายเดือนก่อน

    Could you please teach again but Nestjs with Nextjs 14 and Authjs v5 💯💯

  • @rain704
    @rain704 2 หลายเดือนก่อน +1

    Theme name?

    • @SakuraDev
      @SakuraDev  2 หลายเดือนก่อน

      Hi It is bearded theme

  • @nambarjintumenbayar3599
    @nambarjintumenbayar3599 4 หลายเดือนก่อน

    I’m extracting custom jwt token from useSession session but it is undefined until f5/refresh/ any idea why?

    • @SakuraDev
      @SakuraDev  4 หลายเดือนก่อน

      If you want to alter the shape of your token, you get undefined. I have a video about how to fix that on version 4, the idea is pretty the same: th-cam.com/video/fYObrr3jf0w/w-d-xo.html

    • @nambarjintumenbayar3599
      @nambarjintumenbayar3599 4 หลายเดือนก่อน

      @@SakuraDev exactly doing this but usesession undefined until refresh, server session always one session behind. Changing user will return previous user token

    • @nambarjintumenbayar3599
      @nambarjintumenbayar3599 4 หลายเดือนก่อน

      Next auth so freaking buggy and under documented

    • @nambarjintumenbayar3599
      @nambarjintumenbayar3599 4 หลายเดือนก่อน

      Cannot even find in whole internet about custom auth implementation without damn 3rd party librariy

    • @nambarjintumenbayar3599
      @nambarjintumenbayar3599 4 หลายเดือนก่อน

      @@SakuraDev finally solved. Had to add location.reload() on both signOut, signIn function seems like next auth v5 bug.

  • @fedesolanes2189
    @fedesolanes2189 6 หลายเดือนก่อน

    if i have my webapp with the previous version (v4), do you recommend upgrading it to v5? or u think is not worth it?

    • @MouseCodes
      @MouseCodes 6 หลายเดือนก่อน +2

      It's still in beta so wait

  • @Zeddted
    @Zeddted 6 หลายเดือนก่อน

    Good but why not in Javascript for easy understanding

  • @vernevens1598
    @vernevens1598 5 หลายเดือนก่อน

    What do I need to delete to get rid of Google and just use username and password? I don't want Google collecting my user's information and selling it. I don't trust Google.

  • @francejardinevisarra8504
    @francejardinevisarra8504 6 หลายเดือนก่อน

    broooo please the credential.s and callbacks and there types

    • @francejardinevisarra8504
      @francejardinevisarra8504 6 หลายเดือนก่อน

      plesae notify us when u done making the full course of auth 5, with the email verification, 2FA, reset and change pass

  • @jamescardona11
    @jamescardona11 4 หลายเดือนก่อน

    Waht is your VSCode Extension?

    • @SakuraDev
      @SakuraDev  4 หลายเดือนก่อน

      Hi, 😊 👋 Which extension?

    • @jamescardona11
      @jamescardona11 4 หลายเดือนก่อน

      @@SakuraDev Thank you for your reply and content; the theme extension.

    • @SakuraDev
      @SakuraDev  4 หลายเดือนก่อน

      @@jamescardona11 Thanks 🙏 it is bearded theme

  • @juliushernandez9855
    @juliushernandez9855 6 หลายเดือนก่อน

    Can i use it now in real project?

    • @SakuraDev
      @SakuraDev  6 หลายเดือนก่อน +1

      It is still beta. But I think it will be stable soon

  • @A03L
    @A03L 6 หลายเดือนก่อน

    No authorization ? 😢
    That's very much needed in 80% of modern apps

  • @aryaadinulfadlan8998
    @aryaadinulfadlan8998 4 หลายเดือนก่อน

    you are not protected the page / route.
    you only rendered specific content based on session value.
    the routing can be still acessed. disappointed me.

    • @SakuraDev
      @SakuraDev  4 หลายเดือนก่อน +1

      Fixed that in the new upcoming video.

    • @aryaadinulfadlan8998
      @aryaadinulfadlan8998 4 หลายเดือนก่อน

      @@SakuraDev sure, go ahead

    • @user-tp8wp5zv2n
      @user-tp8wp5zv2n 3 หลายเดือนก่อน

      @@SakuraDev When will you have the solution?😄

  • @khandoor7228
    @khandoor7228 6 หลายเดือนก่อน

    Can we add mongodb for storing users?

    • @SakuraDev
      @SakuraDev  6 หลายเดือนก่อน

      Yes You can. you just need to configure MongoDB adapter

    • @tomasapochian8117
      @tomasapochian8117 6 หลายเดือนก่อน

      Hi there, have you been able to setup the mongoDB adapter? I am getting edge runtime errors when I call the database.

  • @NardosTilahun-r4z
    @NardosTilahun-r4z 18 วันที่ผ่านมา

    When I try to use argon2 for hashing for credential provider sign in it says...
    ⨯ node:crypto
    Module build failed: UnhandledSchemeError: Reading from "node:crypto" is not handled by plugins (Unhandled scheme).
    Please what will be the problem
    I think am using the client side server
    I have used the auth.ts in the root folder but just like they said in the documentation.
    I have used argon2 for registering but for provider sign in to use argon2 to compare the password it is not allowed me as argon2 use crypto
    my auth.ts in the root project

    • @SakuraDev
      @SakuraDev  18 วันที่ผ่านมา +1

      Can you share your code?

    • @NardosTilahun-r4z
      @NardosTilahun-r4z 18 วันที่ผ่านมา

      @@SakuraDev
      import { PrismaAdapter } from "@auth/prisma-adapter";
      import NextAuth from "next-auth"
      import Google from "next-auth/providers/google"
      import prisma from "./prisma/client";
      import CredentialsProvider from "next-auth/providers/credentials";
      import { signInSchema } from "./schema";
      import argon2 from 'argon2';
      import { ZodError } from "zod";
      const credentialsConfig = CredentialsProvider({
      name: "Credentials",
      credentials: {
      email: { label: "email", type: "email", placeholder: "Email" },
      password: { label: "Password", type: "password", placeholder: "Password" },
      },
      authorize: async (credentials) => {
      const result = signInSchema.safeParse(credentials)
      if (!result.success) {
      return null;
      }
      const { email, password } = result.data;
      try {
      const user = await prisma.user.findUnique({
      where: {
      email: email
      }
      })
      if (!user) {
      throw new Error("user not found")
      }
      const isMatch = await argon2.verify(user.password!, password);
      if (!isMatch) {
      throw new Error("User not found.")
      }
      return user;
      } catch (error) {
      if (error instanceof ZodError) {
      return null
      }
      return null;
      }
      }
      })
      export const { handlers, signIn, signOut, auth } = NextAuth({
      adapter: PrismaAdapter(prisma),
      providers: [Google,
      credentialsConfig
      ],
      session: {
      strategy: "jwt",
      }
      })

    • @SakuraDev
      @SakuraDev  17 วันที่ผ่านมา

      I just run your code but i didn't get this err. It works for me!!