Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login session in React

Tags:

reactjs

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.

like image 637
Jolly Avatar asked Aug 08 '26 07:08

Jolly


1 Answers

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?

like image 165
Abhi Burk Avatar answered Aug 10 '26 22:08

Abhi Burk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!