Login Authentication in React.js with Redux | MERN Stack Project

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

КОМЕНТАРІ • 69

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode  2 роки тому

    Part 9 of The MERN Stack Project Series - In this lesson, we add login authentication to our the React app of our MERN Stack Project. We will integrate our login form with Redux and RTK Query. This tutorial is not for beginners. If you are a beginner, check out my full courses all in one playlist here: ua-cam.com/play/PL0Zuz27SZ-6M1Uopt6_VL3gf3cpMnwavm.html

  • @ernestlin767
    @ernestlin767 9 місяців тому +3

    In my case, after adding dispatch(apiSlice.util.resetApiState()) inside inQueryStarted, isSuccess property of useSendLogoutMutation() won't be true anymore, so I can't return the beginning page. How can I handle the problem?

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

      yea i encountered the same problem that isSuccess always defaults to 'false' because sendLogout clears the apiSlice like you said. I just made a custom handleLogout function { sendlogout() navigate("/") }

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

      ya I got the same problem, either you cane remove dispatch(apiSlice.util.resetApiState()) or you can use your custom isSuccess state or use setTimeOut and wait till navigate then reset the state like, setTimeout(() => {
      dispatch(apiSlice.util.resetApiState())
      }, 1000)
      though I am still getting value of data as null in const { data } = await queryFulfilled
      refer code from next lessong in authApiSlice

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

      ya I got the same problem, either you cane remove dispatch(apiSlice.util.resetApiState()) or you can use your custom isSuccess state or use setTimeOut and wait till navigate then reset the state like, setTimeout(() => {
      dispatch(apiSlice.util.resetApiState())
      }, 1000)
      though I am still getting value of data as null in const { data } = await queryFulfilled
      refer code from next lessong in authApiSlice

    • @Harsh-s2d
      @Harsh-s2d 23 дні тому

      @@babenshin7841 Your method works thanks. actually isLoading remains true and isSuccess remains false.

  • @regilearn2138
    @regilearn2138 2 роки тому +3

    Hi Dave,In Multi-Step Form how to keep filled data,When we are go back and forth due to page refresh we lost the previous filled data ?,Please help me on this,What is the best practice in industry

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +2

      I have not published a multi-step form tutorial for React, but yes, you can keep the state when changing screens of the form. That is not the same as refreshing the page though. I do have a tutorial that shows how to keep the user data entered into the form after a page refresh - Look at the useInput and useLocalStorage hooks in this tutorial: ua-cam.com/video/eQrbjvn_fSc/v-deo.html

    • @andifaizal6848
      @andifaizal6848 2 роки тому

      Why you can make dynamic form or use local storage to save value from user input?

    • @regilearn2138
      @regilearn2138 2 роки тому

      @@DaveGrayTeachesCode Appreciate your reply Dave and please do video on multistep form and data persistence in page refresh.

  • @alexandercvetkov4269
    @alexandercvetkov4269 2 роки тому +6

    Soon I will start learning React and your channel is definitely at the top of the list. Thank you for doing this.

  • @CodeWithSahand
    @CodeWithSahand 2 роки тому +1

    very useful and well explained

  • @technoinfoworldwide2329
    @technoinfoworldwide2329 2 роки тому +2

    Make a mern project with backend microservice architecture with using typescript.I didn't find these all things in youtube

  • @kevl7129
    @kevl7129 2 роки тому +2

    Thanks again Dave. As a user of 'old style Redux' who is refactoring an app I was about to ask how, as well as sending the token to API endpoints, I could check if there is a token in state because I currently conditionally render some header links based on auth status (token and an 'isLoggedIn' boolean). Instead I looked at our previous work and managed to create the extra state and a relevant selector for use in components. Keep up the amazing work!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +3

      You nailed it, Kev! We will be doing the same in an upcoming lesson on Role-Based Access Control and Permissions. We will providing not only different header links but also frontend routing based on the role of who is logged in.

  • @lobanovkirill
    @lobanovkirill 2 роки тому +2

    Hi Dave!) Thanks for sharing your skills) Can you show how to implement Role Based Access Control or maybe Attribute Based Access Control system?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +4

      That is still coming in this series. Some of the prerequisites for this series mentioned in the first video have this as well. We will be implementing role-based access control and permissions.

  • @nanonkay5669
    @nanonkay5669 2 роки тому +1

    Is it just me or rtk query is just a bit painful to work with? The API is kinda overwhelming and difficult to master

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      Once you get the hang of it, I think you'll find it is pretty good! View the RTK builder endpoints as your API layer to match your backend.

    • @nanonkay5669
      @nanonkay5669 2 роки тому

      @@DaveGrayTeachesCode I've looked through the docs for rtk query and goodness, it's a lot to take in. It's very complicated and advanced stuff that you'll mostly likely not be able to get started quickly. A lot is happening

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      @@nanonkay5669 yes, as a prerequisite to this MERN Project course, I listed my Redux full course. It helps to complete that first.

  • @waleedsharif618
    @waleedsharif618 2 роки тому +3

    Could you make react testing videos using jest and react testing library ? And also testing redux actions/reducers and action creators

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +2

      Great requests, Waleed! 🙏💯

    • @raymondmichael4987
      @raymondmichael4987 2 роки тому +2

      I agree, with the huge amount of good information he has regarding react, testing will be a wiser next series

  • @Clash-Roblox
    @Clash-Roblox 11 місяців тому

    What happens if user copy the refresh token in cookie before log out and refresh the access token? How can we handle this stuff sir?

  • @MrZiyak99
    @MrZiyak99 2 роки тому +1

    if we store the access token in memory this would also mean that when we reload the app on the login page we will have to login each time? even if we use the refresh token to generate a new auth token on the login screen that would basically flash the login screen for a bit and then redirect us to the authenticated screen we specify correct?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      I will be applying a persistent login strategy in the next lesson or two for this series. To get an idea of how it works, you can check out the prerequisite React Login videos for this series listed in the description - especially the persistent login video. With the prefetch component we already have in place for this project, you will be able to refresh from any protected page suprisingly fast. Any delay will depend on connection speed because - as you mentioned - refreshing the page reloads any React app.

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

    some advanced redux s**t right there, and i love it. :p thanks dave. pardon my french. i got excited.

  • @arunkumar-tn5gu
    @arunkumar-tn5gu 2 роки тому +1

    Hi. Iam waiting for this video

  • @mahamadounouridinemamoudou9875
    @mahamadounouridinemamoudou9875 2 роки тому +1

    I'm sure about what I will expect in this video, thanks you very much for this

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

    Server not set cookies on client side. How to fix this issue?

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

      Fixing by setting secure: true and fetchBaseQuery option credentials: "include"

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

    How to persist the token inside the redux after the hard reload of the page?

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

      I do have videos that cover the persist strategy. Always worth searching my channel, but here is one link: ua-cam.com/video/-JJFQ9bkUbo/v-deo.html

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

    Really appreciate your efforts to give such great content for free!
    Had the following doubt, could you please check? The token that we use is sensitive information and can't be stored in redux state right?

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

      The refresh token should not be in state, but you can use the access token in state. That's what we do here. Do not put either in localStorage. I avoid that.

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

    You should never store your refresh or access tokens in the client. This is really bad practice.

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

      Never in local storage. The client does need to send them back somehow. That's the reason for the httpOnly secure cookie. I've provided references with the videos. Do you have references that disagree?

  • @AhSoh7091
    @AhSoh7091 2 роки тому

    Hi Dave, why we can use build.mutation in 'Get' method for the refresh? I thought it is a standard code for mutation in POST, PUT, PATCH methods in building.mutation and GET method in build.query?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +4

      This is an excellent question! We can specify any http method we want in a mutation although - as you mention - the most common are POST, PUT, PATCH, and DELETE. We send a GET request for the refresh endpoint because we are not sending anything in the body of the request as we would with POST and the others. That said, it is still a mutation - because mutation refers to our state - and we will be replacing the access token in our Redux state with the response we get from the request. I hope that helps!

    • @AhSoh7091
      @AhSoh7091 2 роки тому

      @@DaveGrayTeachesCode thanks sharing your knowledge

  • @alienx2367
    @alienx2367 2 роки тому

    Hi Dave ... I would appreciate if you could please guide me on the order of playlist I should follow in order to learn Complete React properly
    There seems to be four playlist
    1. React Tutorials
    2. React Redux Toolkit
    3. React login registration and authentication
    4. React hooks

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      I suggest React Tutorials as it holds most of the other React tutorials as well. React Tutorials starts with my full course and then covers most of the React hooks.

    • @alienx2367
      @alienx2367 2 роки тому

      @@DaveGrayTeachesCode alright thanks 👍🏻

  • @samobaidi5000
    @samobaidi5000 2 роки тому

    Dave you are really doing great Job thank you for spreading the knowlodge , i hope you will add the login using google account also and reset password by email.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      Thanks for the requests! 💯 That may go above and beyond this series, but your requests will make nice additional add-ons. 🚀

    • @samobaidi5000
      @samobaidi5000 2 роки тому

      @@DaveGrayTeachesCode thank you so much for your reply , it will be great because it will make it such a compelete tutorial especially that it will be connected with the fire base and also the register might be with an email or gamil and also the password recovery. thank you again. BIG RESPECT

  • @samiullahsheikh5015
    @samiullahsheikh5015 2 роки тому

    9:35 Why are you using mutation for GET endpoint?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      Will the refresh request have a body that would normally be sent with POST, UPDATE, DELETE, or similar HTTP methods? No, it will only send the cookie that contains the refresh token. At the same time, it will mutate our app state by receiving a new access token in response to the request. We could send the cookie with a POST request method or others, but it is not necessary.

  • @alielb2130
    @alielb2130 2 роки тому +1

    Would it be awesome in future to have Microservices with MERN stack, that would be killer, great content Dave as always

  • @mohamaddabra6252
    @mohamaddabra6252 2 роки тому

    Best Fulldiv and Mentor I've ever seen! thanks a lot for your Hardwoek

  • @pablo20237
    @pablo20237 2 роки тому +1

    Thanks

  • @shakilab55
    @shakilab55 2 роки тому +1

    great series! how many videos are left in this mern list ?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому

      Thank you, Shakil! Not many left. I never count out how many. I just go where the required content leads. We are getting close! 💯🚀

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

    {2023-03-24}, {2023-03-25}, {2023-03-30}

  • @onelook1870
    @onelook1870 2 роки тому

    Hey Dave when foundUser.password is passed to bycrpyt.compare it says data and hash arguments required. I was able to solve it by adding .select ('+password')

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 роки тому +1

      I don't have an error? Compare to my source code at the course resources link and see if you have any differences in your code.

    • @onelook1870
      @onelook1870 2 роки тому

      @@DaveGrayTeachesCode I will have a look.

    • @onelook1870
      @onelook1870 2 роки тому

      @@DaveGrayTeachesCode will you be doing pagination