刷新浏览器后,Angular2保留敏感信息 [英] Angular2 retain sensitive information after browser refresh

查看:113
本文介绍了刷新浏览器后,Angular2保留敏感信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的登录操作将返回有关已登录用户的信息(无论是否为admin),例如(isAdmin: true)我可以在组件之间保留此信息,直到浏览器刷新或类似操作为止.但是刷新浏览器后,我丢失了此信息.我很困惑如何保留此值.

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.

我正在使用localStoragesessionStorage保存一些非敏感信息.但是此信息很敏感,因此不应允许用户编辑/查看此值.

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.

有什么方法可以使用angular2完成此操作吗?

Is there any way to accomplish this using angular2?

推荐答案

每次启动应用程序时,我都会对服务器或您具有用户信息的位置进行API调用.因此,当我刷新应用程序时,我可以从第一手获得信息,而不必将其存储在会话中,只需将数据存储在一个对象中并使用它即可.

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.

登录时,生成令牌并将其保存在会话中,并将其与我前面提到的API调用一起发送.

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

那是我的方法:

  1. 登录->生成令牌
  2. 商店令牌
  3. API调用获取用户的信息传递令牌(在应用程序初始化中)

希望它可以帮助或至少给您一些有价值的想法...让我们知道您如何解决您的问题! :D

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

这篇关于刷新浏览器后,Angular2保留敏感信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆