问题
I am using email/password authentication via Firebase, so currently I only have authenticated user and non-authenticated user. But for the app, I would like to have admin, moderator, user and guest four different kinds of role.
I did some research, but could not find any existing example or logic to do so. Here are my initial thoughs, but not sure if it is feasible. Basically two steps:
- Create a table in firebase called User, while Firebase record the email/password, I also push the data(email/password), and role information to the table.
- In the route, check if the user has the appropriate role to access the certain page
Any other better way to do it? Any idea would be appreciated!
回答1:
I had similar issue while working with role based authorization. I followed same pattern of saving users role and then retriving it when needed. If you are using ui-router for routes then probably you can use angular-permission module which works on the same concept and is easy to use.
You can find that module here: https://github.com/Narzerus/angular-permission
来源:https://stackoverflow.com/questions/32217210/role-based-authentication-with-firebase-and-angularjs