Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 应用程序与用户_Firebase_Firebase Realtime Database_Firebase Authentication - Fatal编程技术网

Firebase 应用程序与用户

Firebase 应用程序与用户,firebase,firebase-realtime-database,firebase-authentication,Firebase,Firebase Realtime Database,Firebase Authentication,我正在开发一个应用程序,其中将有在应用程序中具有特定权限的用户,我将在saas模型中提供,我的问题是,我是否应该为使用我的应用程序的每个公司在firebase中创建一个项目,或者是否有任何方法可以在firebase数据库中控制该项目?您必须使用自定义令牌声明,以便为您的用户设置不同的权限 在规则中,可以设置如下内容: { "rules": { "adminContent": { ".read": "auth.token.premiumAccount === true",

我正在开发一个应用程序,其中将有在应用程序中具有特定权限的用户,我将在saas模型中提供,我的问题是,我是否应该为使用我的应用程序的每个公司在firebase中创建一个项目,或者是否有任何方法可以在firebase数据库中控制该项目?

您必须使用自定义令牌声明,以便为您的用户设置不同的权限

在规则中,可以设置如下内容:

{
  "rules": {
    "adminContent": {
      ".read": "auth.token.premiumAccount === true",
      ".write": "auth.token.premiumAccount === true",
    }
  }
}
然后,您可以使用admin node.js sdk为该用户创建具有该自定义声明的自定义令牌:

admin.auth().createCustomToken(uid, {premiumAccount: true});
然后,您可以在登录后将customToken发送到客户端应用程序。确保在后端验证ID令牌,然后验证用户是否满足权限要求:

var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider)
  .then(function(result) {
    // User is signed in. Get ID token.
    return result.user.getToken();
  })
  .then(function(idToken) {
    // Send ID token to backend.
    $.post(
      '/setCustomAttributes',
      {
        idToken: idToken
      },
      function(data, status) {
        // Check if custom token is returned.
        if (status == 'success' && data) {
          var json = JSON.parse(data);
          if (json && json.customToken) {
            // User is eligible for upgrade. Set custom attributes on the user
            // via custom token sign-in.
            firebase.auth().signInWithCustomToken(json.customToken);
          }
        }
      });
    }).catch(function(error) {
      console.log(error);
    });

我不明白你的应用程序到底是如何工作的?不同的公司使用不同的数据?或者不同的公司使用相同的数据?堆栈溢出并不是寻求关于如何构建应用程序的广泛建议的合适地方。考虑向FixBASE谷歌集团投稿。当您对为实现应用程序而编写的代码有特定问题时,请返回堆栈溢出。