简体   繁体   English

基于Angular 2角色的身份验证

[英]Angular 2 role based authentication

I know this question is answered but it doesn't clarify my doubt. 我知道这个问题已经回答,但是并不能澄清我的疑问。

I have an angular app with multiple module. 我有一个带有多个模块的角度应用程序。

I am getting the role when user log in to app and setting the role in shared service. 当用户登录应用程序并在共享服务中设置角色时,我将获得该角色。

I tried creating a shared service and share the role through shared service throughout the app. 我尝试创建共享服务,并通过整个应用程序中的共享服务共享角色。 This approach works fine but on refresh of page shared service data is getting cleared. 这种方法效果很好,但是在刷新页面时共享服务数据已清除。 So role is getting destroyed. 因此角色正在被摧毁。

Please let me know how can I implement role based authentication without storing role in browser storage (because of security reasons) and any third party module 请让我知道如何在不将角色存储在浏览器存储(由于安全原因)和任何第三方模块中的情况下实现基于角色的身份验证

If you don't want to store user role on your browser then you can use user id provided by your database and store it as cookie. 如果您不想在浏览器上存储用户角色,则可以使用数据库提供的用户ID并将其存储为cookie。

After that you have to set function that checks if cookie is present or not and works accordingly. 之后,您必须设置检查Cookie是否存在并相应运行的功能。 Try using passport.js for this purpose. 为此,请尝试使用passport.js

Hope this helps. 希望这可以帮助。

you must use the browser storage to store some data. 您必须使用浏览器存储来存储一些数据。 the options here which date you will store, I prefer storing the token instead of user credentials, and give that token a specific period of time after that time delete it from your database and so you have not to store any credentials in the browser storage 在这里您要存储日期的选项中,我更喜欢存储令牌而不是用户凭据,并在该时间后的特定时间段内将该令牌从数据库中删除,因此您不必在浏览器存储中存储任何凭据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 6基于角色的身份验证 - Angular 6 Role based Authentication ASP.NET Core 3.1 + Angular 9 基于角色的身份验证 - ASP.NET Core 3.1 + Angular 9 role based authentication 基于JWT身份验证和角色路由到Express中的多个Angular 7项目 - Routing to multiple Angular 7 projects in Express based on JWT authentication and Role Firebase 角色认证 Angular - Firebase role authentication Angular 当管理员角色应该能够创建子帐户时,如何在 Angular/Ionic 中使用 firebase 编写基于角色的身份验证? - How is it possbible to program a role based authentication with firebase in Angular/Ionic, when the admin role should be able to create subaccounts? Angular 2中基于角色的UI - Role Based UI in Angular 2 Angular 基于角色的登录 - role based login in Angular 访问管理组件正在使用 jwtHelper 在 angular 中实现基于角色的身份验证 - Access to the admin component am implementing role based authentication in angular using jwtHelper 我们如何才能对 angular 应用程序的某些功能进行基于角色的身份验证? - How can we approach to have role based authentication to some of the functionalities of angular app? Angular 4路由-基于角色的访问 - Angular 4 Routing - Role based access
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM