skip to Main Content

I am working on a project and I’ve created a login page. I want to authenticate the user and keep the user logged in until he logs out. How do I do that using React, Express and MongoDB?

2

Answers


  1. You can use browser’s localstorage and save the userInfo there and when he logs out you can clear the storage. You can check this set localstorage

    Or you can make it from the server side with session-express and redis express sesson

    Login or Signup to reply.
  2. Proper basic implementation here is the followings:

    • backend authentication service that is checking credentials
      • this can be implemented in express and mongodb
    • the authentication service stores the user login status in session and cookies
    • on each render, the react app first ask express app to get user login status
      • if the user was logged in then show user dashboard
      • if the user wasn’t logged in then show login page
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search