Role based authentication with firebase and angula

2019-07-10 17:13发布

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条回答
爷、活的狠高调
2楼-- · 2019-07-10 17:43

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

查看更多
登录 后发表回答