2

I'm creating a portal in React, and I need to allow login/logout of users, where if you are logged you can see some pages, otherwise you can't.

So far I've thought about having a variable 'isLogged' in the state of each component which need the user to be logged to be seeen, and pass the variable in the props among the these components. Then, I saw I can also use the localStorage to save this variable (I'm ok with the fact that the user would remain logged as long as he will clear his chace). The question I have is: is this ok, or it is not the right way to manage the session user (also considering security issues)? If so, which is the correct one?

If it's useful to know, I'm not using Redux, and probably the portal will exploit only https protocol.

Jolly
  • 1,678
  • 2
  • 18
  • 37
  • 1
    You can use the 'localStorage' or the cookie for that. For my projects, I don't use localStorage because that doesn't work with private navigation. – Damien Feb 26 '18 at 12:08

1 Answers1

3

It may be very late but still You could try out this which is one of the best way to handle auth user

React - What is the best way to handle authenticated/logged in state?

Abhi Burk
  • 2,003
  • 1
  • 14
  • 21
  • 1
    Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Kalle Richter Mar 24 '19 at 10:52
  • I am using Python Flask for the back end. Can I have sessions managed by Python Flask and all requests to the backend will get a json information back which will also include session variables needed for the front end - is this an good practice – DataGuru Aug 20 '20 at 07:33