简体   繁体   中英

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.

After that you have to set function that checks if cookie is present or not and works accordingly. Try using passport.js for this purpose.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM