Add Authentication to Next.js in 10 mins with OAuth (Google, Github...)

Поделиться
HTML-код
  • Опубликовано: 10 июл 2024
  • Adding Authentication to your React or Next.js application can be hard sometimes, especially if you're dealing with OAuth providers like allowing your users to log in with their Google account or even using regular credentials like Email and password it will turn into a huge mess when trying to deal with different aspects of authentication.
    ⭐ Timestamps ⭐
    00:00 Intro
    00:51 NextAuth.js Library
    02:03 NextAuth Setup
    04:16 Login with Credentials (Email & Password)
    06:27 Adding Login with Google & Github config
    10:23 Generated Login page
    12:25 Using a Custom Login Page
    14:42 Google and Github Login
    16:25 Managing User Session
    18:13 Protected routes & Redirects
    -- Special Links
    ✨ Join Figma for Free and start designing now!
    psxid.figma.com/69wr7zzb1mxm
    👉 ✨ Join Figma For Professionals And Start Designing with your Team ✨
    psxid.figma.com/ucwkx28d18fo-...
    💻 Clone the Next.js Auth Repo
    github.com/ipenywis/nextjs-auth
    🧭 Build Login/Register API Server w/ Authentication | JWT Express AUTH using Passport.JS and Sequelize
    • Build Login/Register A...
    🧭 Turn Design into React Code | From prototype to Full website in no time
    • Turn Design into React...
    🧭 Watch Tutorial on Designing the website on Figma
    • I Design a onecolor We...
    🧭 Watch Create a Modern React Login/Register Form with smooth Animations
    • Create a Modern React ...
    🧭 Debug React Apps Like a Pro | Master Debugging from Zero to Hero with Chrome DevTools
    • Debug React Apps Like ...
    🧭 Master React Like Pro w/ Redux, Typescript, and GraphQL | Beginner to Advanced in React
    • Master React Like Pro ...
    🧭 Learn Redux For Beginners | React Redux from Zero To Hero to build a real-world app
    • Debug React Apps Like ...
    🧭 Introduction to GraphQL with Apollo and React
    • Introduction to GraphQ...
    🐦 Follow me on Twitter: / ipenywis
    💻 Github Profile: github.com/ipenywis
    Made with 💗 by Coderone

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

  • @ZiaCodes
    @ZiaCodes Год назад +24

    Why to make "IsloggedInServer and the IsLoggedClient" function and add to every page, it will be repeating the same thing.
    Isn't the middleware a best option for this type?

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

    Very practical way of using next-auth with next js . Thanks

  • @sholavandan81
    @sholavandan81 Год назад +13

    The github code is missing the next-auth specific implementation for Google & github. Can you please push the code into the repo? It would help us to go through the code and implement.

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

    Excellent video!

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

    Question: for authButtonsFiles - I am not certain why there are two buttons ( google / github ) when it could have been refactored into one for instance ?
    Did you had / do you have specific reasons or was it made just on the fly for the purpose of the video ?

  • @nerophase
    @nerophase 10 дней назад

    very good tutorial.. thanks!!

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

    Thank you kindly!

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

    amazing video, thank you so much it helped me out a lot!!

    • @Gamer-gw6nj
      @Gamer-gw6nj 5 месяцев назад

      Could you help me find the previous video?

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

    Great job dude 🎉 tks

  • @Adrian-mu8gg
    @Adrian-mu8gg Год назад

    what if i use the credentials provider but forget password? does next-auth got any thing out of the box to handle that? like email resend reset password token?

  • @brunomartins3055
    @brunomartins3055 5 месяцев назад

    top man keep it cool great job

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

    can you explain us how to customize the sign in form?
    like the GoogleSignInButton and GithubSignInButton
    thanks

  • @aliafarinifard
    @aliafarinifard 4 месяца назад

    Great Job... I love your teach

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

    Thank you so much, its works

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

    Nice video. please mind sharing what font and theme you are using for vscode?

  • @dachewster9999
    @dachewster9999 Год назад +20

    You didn't use the latest version which is AuthJs, and you didn't use middleware, so what you showed is not very good

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

      ?

    • @user-sf9su6xb6q
      @user-sf9su6xb6q 6 месяцев назад +1

      And didn't deploy on vercel, so credentials won't work

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

    when you "contiune with Google" does your data get saved on the prisma database, because when i try this, I cannot find the user data in my prisma studio

  • @r34ct4
    @r34ct4 2 дня назад

    Any idea how we can deploy this on Google Cloud Run (with variables & secrets) and/or Vercel? My ENV variables do not seem to work on either. Thanks man

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

    how about next js next auth with nest js as a backend.....

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

    Hi, in production the login doesent work, any idea why ? I use same urls for dev and production build, dev works great, production (local) not.

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

    great tutorial! question - how do you use hooks inside a condition? isnt it against react hooks rules?

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

    how do you sign out of the github API? i can sign out on my app, but i'm still logged in through github :(

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

    Great tutorial, does the Google login and Credentials login handle the refresh token, CSRF etc !!!

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

    I have a problem with authentication, how can I automatically cancel authentication? when i am logged in and i close windows then open it but it logs in by itself

  • @LemanGahramanova-kh8fb
    @LemanGahramanova-kh8fb 2 месяца назад

    i have an error: Error with Permissions-Policy header: Unrecognized feature: 'ch-ua-form-factor'.
    How i can fix this problem?

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

    Which vscode theme you are using ?

  • @sleechigo3759
    @sleechigo3759 5 месяцев назад

    Hi, thanks for the nice video. I notice that in production, as you click the button to use google or github, chrome flags your site as dangerous, why is that, any way to fix it.

  • @alexanderbrewster3595
    @alexanderbrewster3595 4 месяца назад

    thank you for the help, i have been struggling with authentication for weeks

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

    hey! You explained the things in simple and understandable word, quite helpful. well I got stuck in an issue, while I'm trying to signIn with google it gives me error message "Try signing in with a different account", I'm pretty sure I have followed all steps and cross checked multiple times too, not sure why this error still there. Can you provide me any suggestions or have any idea why it behave like this.

  • @tomasburian6550
    @tomasburian6550 5 месяцев назад +2

    You forgot to show us how to set up the authorizatiion for GitHub, but otherwise... good video. I've learned a lot.

  • @hamzandev9482
    @hamzandev9482 Год назад +4

    How i can store the user information to database like postgres if the user signed in using GitHub or other providers?

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

      Same, and what if I want to remove any user how can I do that

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

    Why don't you need an adapter for the auth configs?

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

    Hey man, nice explanation. Thank you. But Is there a way do the same kind of email checking like in the credentials provider with the Google Provider? Let's say I have a user table and when someone trying logging in with Google, their email needs to be cross-matched with a user from the user table. if matched they should be allowed to login otherwise redirect to login page. Can anyone suggest a solution for this problem? TIA

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

    what theme is that

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

    thanks bro

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

    Best way for a custom backend to integrate with Google provider, ideally i need mmy backend to track accounts through the creation of user entities in the backend as each user will have their own data.

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

    Have you tried the refreh token strategy?

  • @sirvoya2357
    @sirvoya2357 27 дней назад

    how can i use DiscordProvider?

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

    good video sir

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

    nice video

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

    hi, i did that but after try to login i have error below
    Try signing in with a different account.
    expected 200 OK, got: 403 Forbidden
    can't find anything for that

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

    where did you pass the nextauth secret?

  • @mishos5428
    @mishos5428 10 месяцев назад +2

    Great video. Where can I find the source code of this particular video?😃

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

    ✨👌

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

    I could login using Github but it didn't redirect me to the "dashboard || timeline || etc" I stay in the same page with my session started. How can I do to redirect after login with github/google ?

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

      I too have the same issue sir, any update on your side?

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

    Good day greetings

  • @darkemperor9006
    @darkemperor9006 13 дней назад

    Kindly make new video using authjs

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

    Nice tut Bruh, bbut I can't get the Git Repo, I looked, up and down, but did not see it!

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

      github.com/ipenywis/nextjs-auth

  • @Gamer-gw6nj
    @Gamer-gw6nj 5 месяцев назад

    Where is the previous video where he built the whole clone? @CoderOne

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

    2FA would make it even more secure

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

    how can i get te toke.. ehe

  • @kiliusz
    @kiliusz Год назад +3

    said 5min
    title 10min
    video length 20min

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

    i dont understand u add a lot of code before...

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

    it took me over 1 h and i stil dont have that....

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

    source code? github ?

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

      github.com/ipenywis/nextjs-auth

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

    6:03 coding and talking is hard.

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

    Title: Add Authentication to Next.js in 10 mins
    Video Duration: 20 mins.

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

      It's called a "VIDEO TUTORIAL". So I have to go through and explain all the bits and details so everyone from beginner to advanced can easily understand and walk away happy. It says 10mins because anyone can add auth in 10mins but it doesn't necessarily mean that the video will be less than 10mins. The video is meant to make people understand not just implement it and walk away!

    • @Gamer-gw6nj
      @Gamer-gw6nj 5 месяцев назад

      @@CoderOne I want to explore the previous video where you build the whole twitter clone.
      Could you give me the link of that video please?
      I need it urgently.

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

    its 20 min

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

    unclear as hell

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

    these captions are irritating