Authenticate Your Next.js Apps Using Firebase: Complete Guide

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 พ.ย. 2023
  • Github: github.com/coderyansolomon/fi...
    In this tutorial, I cover how to authenticate users within your Next.js app router applications using Firebase. I cover signing in, signing out, and signing up.

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

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

    To prevent a home page to flash just use 'return router.push("...")' instead of 'router.push("...")'. Thus you won't see the home page if you're not signed in. Also can use 'loading' variable coming second from useAuthState hook to render some fallback component. So there won't be any need of adding session storage item.

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

    Thanks for sharing this guide!
    You made a comment about making errors toward the end of the video. I just came here to say that I was looking for this video, and there were a few available... but the other ones I looked at were guys that jump-cut through their mistakes, and they'd copy and paste all of their code so you wouldn't see them typing.
    Those videos are awful to follow along with. Yours is relatable. Keep doing it the way you're doing it! We're here because we're making mistakes too.

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

      Thank you for the kind words, very much so appreciated!

  • @yashraj4855
    @yashraj4855 6 หลายเดือนก่อน +4

    Awesome guide! Got my thing working in one go. Thanks a lot 😊.

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

      Happy to hear it!

  • @Rawailsakib
    @Rawailsakib 3 หลายเดือนก่อน +2

    Rayan your best is that you always reply to your learners without hurting them this is your best then your skills

    • @coderyan
      @coderyan  3 หลายเดือนก่อน +1

      Thank you!

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

      @@coderyan your welcome man!

  • @MrBlazzerBoy
    @MrBlazzerBoy 6 หลายเดือนก่อน +10

    Also please do one for protecting routes: show those pages only if user is logged in.

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

    Thank you so much, Ryan, this will help me.

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

      You’re welcome!

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

    great video helped me a lot, keep it up

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

      Happy it helped you out

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

    Hi! Thank you for this video! How did you use async/await in client component? I have an error when try it

  • @janeeshafernando6830
    @janeeshafernando6830 5 หลายเดือนก่อน +2

    Thankyou soo much. Its working 😍🥰

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

      Happy to hear it!

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

    Hey thanks Ryan Just wondering... Why are you using .env for the config files? The docs say the cofnig data is safe to be on the front end?

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

    that was awesome and so easy to use

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

      Happy it helped!

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

    Hi Ryan! Thanks for this tutorial. Can you make full example how to use Firebase Auth also using SSR and proper session storage thru whole application? There is a lot of this kind of tutorials were you can find examples how to signin/login/signout but it ends at this step. Thanks a lot!

    • @ionutsandu5913
      @ionutsandu5913 5 หลายเดือนก่อน +3

      I successfully managed to do what you're asking for my company but it was quite tricky. This weekend I will create a repo if you'd like so you can get some help from there.

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

      @@ionutsandu5913Hi! Can you please share your repo/GitHub username. I’m learning firebase Auth it would be great if you could share it. Thanks

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

      @@ionutsandu5913 Very kind of you, if the offer still stands.

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

      @@ionutsandu5913can you share the repo url? Thanks in advance

  • @davidlintin
    @davidlintin 5 หลายเดือนก่อน +3

    27:36 "I'm gunna change this to jsx because I like the Icon better" - also me.

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

      Haha glad you can relate

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

    thanks man, i've been following the official docs but kept on getting errors. Is "react-firebase-hooks" library a must in order to use firebase with next js?

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

    you’re so good can you make a same tutorial but showing user data? or maybe username system?

  • @isagive
    @isagive 3 หลายเดือนก่อน +1

    Thank you brother.
    the userSession solution seems wrong - the useAuthState changes so maybe we need to wrap in a function and wait for it?
    i dont know but it still kicks out a lot of error after routing.
    In anycase, thank you for the hard work
    very helpfull tutorial

  • @Growingmindsetalha
    @Growingmindsetalha 7 หลายเดือนก่อน +3

    why is it giving the res undefined?

  • @Growingmindsetalha
    @Growingmindsetalha 7 หลายเดือนก่อน +4

    it is not adding the user in the data base

  • @tabmax22
    @tabmax22 12 วันที่ผ่านมา

    should firebase env vars be added to vercel platform to a prod app as NEXT_PUBLIC_...?

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

    How would you move the Auth logic into something like an Auth Context?

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

    I have a question, how can i sing up users and set their first and last name?

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

    Thank you for the guide. It helped me a lot!
    The only issue that I had was the errors. The react-firebase-hook did not throw some of my errors automatically.
    I had to get the errors from the hook and then throw it manually.
    Something like this:
    const [signInWithEmailAndPassword, user, loading, error] = useSignInWithEmailAndPassword(auth)
    try {
    const res = await signInWithEmailAndPassword(data.email, data.password)
    if(error){
    throw new Error(error.message)
    }
    reset()
    router.push('/my-chats')
    }
    catch(err) {
    console.error(err)
    }

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

    How can I refresh the user idToken after expiration? How is that process? After 1 hour, the user is not retrieved and no refreshed id is gotten. Please, I'm really stuck in that process 🙏. I'm building a PWA with NextJS and I need the user to always be signed in

  • @Minu_Shalom
    @Minu_Shalom 11 วันที่ผ่านมา

    Hi Ryan! Maybe I'm wrong, but as I know NEXT_PUBLIC will be included in the client-side JavaScript bundle, making them accessible to anyone who can inspect the website's source code.

  • @alikawu7145
    @alikawu7145 21 วันที่ผ่านมา

    Will this make all the components client components?

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

    The home page still flashes when going to the original URL. if the page was to be protected its not.

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

    is this secured to store use in session storage ?

  • @brookt5725
    @brookt5725 3 หลายเดือนก่อน +1

    Have you tried going to / without signing in it displays the content for a short while which is really bad thing

    • @coderyan
      @coderyan  3 หลายเดือนก่อน +1

      Should have covered this in the video, but can be solved in several ways, one of which is by using some loading state

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

      @@coderyan Wouldn't that be redundant to do that on each page

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

      Wouldn’t need to do it at each page. You can do it higher up in the application (e.g in the root component)

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

    Is this going to make all the app a client component?

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

    it's full ClientSide when we use Firebase auth?

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

    Can't we directly use the config js file for the storing values of those variables? Why are we using them as env variables? Is it some kind of convention to do so?

    • @nosrehcorporation
      @nosrehcorporation 6 หลายเดือนก่อน +3

      Safety, you dont want to expose those values in your regular packages

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

      @@nosrehcorporation ok thankyou sir

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

    I am getting an error of module not found in page.js file for config.js file for auth. But I have already made that file.

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

    The thing is you are doing it only in client side

  • @jabedalamakash8558
    @jabedalamakash8558 8 หลายเดือนก่อน +1

    thanks

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

      You’re welcome

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

    I don't get the point, If you make all page use client then why you are using next?

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

      ig he did this for tutorial purpose, we can rectify the code.

    • @ionutsandu5913
      @ionutsandu5913 5 หลายเดือนก่อน +2

      @@scor32k Not really. All firebase hooks need client to run. Having a SSR auth with firebase is quite tricky.

    • @user-hr4rl2cz1h
      @user-hr4rl2cz1h 4 หลายเดือนก่อน

      @@ionutsandu5913 you're right, I don't understand why everyone is making video with NextJS title but just handling the issues same as simple React.

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

    Excellent video as usual. Just one plea from littl ol' England on presentation. Please try to avoid saying "go ahead and" too often. Thanks.

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

    I love you

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

    hey man great video! It gives me an error ''sessionStorage is not defined" when i try to deploy.
    Any idea how to solve it?

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

      'use client';
      add this line in top of your page

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

      @@shreyashraj its already in a client side component :(

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

      @@CptJuke maybe you forgot to import sessionStorage

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

      Hello, I have the same problem, could you solve it?

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

      @@juanpabloarroyochavez7311 sadly no 😞

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

    … Oh. So I have to use hooks and shit… alright. That makes my life easier. I’m used to calling some API instead of FireBase and then storing JWTs. So this is kinda weird. And I’m used to working in SolidJS or Svelte. So this is weird for me.