Firebase身份验证(多种类型的用户) [英] Firebase Authentication (multiple types of users)

查看:50
本文介绍了Firebase身份验证(多种类型的用户)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从React进行身份验证的react.js项目中,但是我有3种具有不同权限的用户类型(超级管理员,供应商管理员,供应商人员).我如何才能从Firebase对其进行身份验证,并知道这是我的Vener管理员或供应商人员等?因为Firebase只是对单一类型的用户进行身份验证!

i am working on a react.js project which authenticate from firebase but i have 3 multiple type of user's in it (super Admin,vendor admin,vendor staff) with different privileges. how can i authenticate them from firebase and get to know this is my venor admin or vendor staff etc ???? because firebase just authenticate single type of user!

推荐答案

您可以通过 Cloud Functions在您自己的服务器上使用Firebase Admin SDK来进行nofollow noreferrer>自定义声明用于Firebase .

You can control access via custom claims using the Firebase Admin SDK on your own server of through Cloud Functions for Firebase.

使用以下方法为特定出价设置声明服务器端:

Set claims server side for a specific bid with a method like this:

admin.auth().setCustomUserClaims(uid, {admin: true}).then(() => {
// The new custom claims will propagate to the user's ID token the
// next time a new one is issued.
});

然后使用分隔管理员和供应商管理员内容的结构来设置数据库:

Then set up your database with a structure that separates admin and vendor admin content:

/
   /admin
      /data for admins here
   /vendorAdmin
      / data for vendor admins here
   /staff
      // data for staff here, or perhaps this data is accessible to all since the admins may need access to it.

在Firebase控制台中,自定义规则以将这些位置限制为包含适当声明的用户:

In the Firebase Console, customize the rules to restrict these locations to those who include the proper claim:

{
  "rules": {
    "admin": {
      ".read": "auth.token.admin === true",
      ".write": "auth.token.admin === true",
    }
    "vendorAdmin": {
      ".read": "auth.token.vendoradmin === true",
      ".write": "auth.token.vendoradmin === true",
    }
    "staff": {
      ".read": "auth.token.staff === true",
      ".write": "auth.token.staff === true",
    }
  }
}

这是一个简化的示例,因此您必须进一步对其进行自定义,以满足您的应用程序的需求.

This is a simplified example, so you'll have to customize it further to meet the needs of your app.

这篇关于Firebase身份验证(多种类型的用户)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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