使用firebase和angularjs进行基于角色的身份验证 [英] Role based authentication with firebase and angularjs

查看:174
本文介绍了使用firebase和angularjs进行基于角色的身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过Firebase使用电子邮件/密码认证,所以目前我只有认证用户和未认证用户。但对于应用程序,我想有管理员,主持人,用户和来宾四种不同的角色。



我做了一些调查,但找不到任何现有的示例或逻辑来这样做。这是我最初的想法,但不确定是否可行。基本上有两个步骤:


  • 在Firebase中创建一个名为User的表格,同时Firebase记录电子邮件/密码,同时将数据(电子邮件/密码)和角色信息。

  • 在路由中,检查用户是否具有访问特定页面的适当角色



还有其他更好的方法吗?任何想法,将不胜感激!

解决方案

我有基于角色的授权时遇到类似的问题。我遵循了保存用户角色的相同模式,然后在需要时进行回溯。如果你正在使用ui路由器的路线,那么可能你可以使用angular-permission模块,这个模块在相同的概念上工作,很容易使用。



你可以找到那个模块这里: https://github.com/Narzerus/angular-permission


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!

解决方案

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

这篇关于使用firebase和angularjs进行基于角色的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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