Search code examples
angularlocal-storagesession-storage

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?


Solution

  • 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