Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 retain sensitive information after browser refresh

My login action returns information about the logged in user if they are admin or not, say (isAdmin: true) I can keep this information between the component until a browser refresh or similar action. But I lose this information after a browser refresh. I m confused how to retain this value.

I am using localStorage and sessionStorage to save some non-sensitive information. But this information is sensitive and the user should not be allowed to edit/view this value.

Is there any way to accomplish this using angular2?

like image 577
Philip John Avatar asked Jan 30 '26 02:01

Philip John


1 Answers

I would make an API call to the server or where you have the user's information each time the App starts. So, when I refresh the App I get the information from first hand and I don't have to store it in sessions, I just store the data in an object and use it.

When you login generate a token and save it in session and send it along with the API call that I mentioned earlier.

That would be my approach:

  1. Login -> generate token
  2. Store token
  3. API call getting user's information passing token (On App init)

Hope it helps or at least gives you some valuable ideas... Let us know how you solve your issue! :D

like image 60
SrAxi Avatar answered Jan 31 '26 18:01

SrAxi



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!