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 Security_Firebase Authentication - Fatal编程技术网

Firebase安全规则没有';创建用户时不允许

Firebase安全规则没有';创建用户时不允许,firebase,firebase-security,firebase-authentication,Firebase,Firebase Security,Firebase Authentication,我使用Firebase$authWithPassword方法进行用户登录。我使用$createUser方法为我的用户创建注册,注册成功后,我更新/users/path上的条目以保存用户名、uid和其他一些详细信息。这是密码 var myDataRef = new Firebase(baseURL + 'datalog/'); var refObj = $firebaseAuth(myDataRef); refObj.$createUser({ email: $scope.emailId

我使用Firebase
$authWithPassword
方法进行用户登录。我使用
$createUser
方法为我的用户创建注册,注册成功后,我更新/users/path上的条目以保存用户名、uid和其他一些详细信息。这是密码

var myDataRef = new Firebase(baseURL + 'datalog/');
var refObj = $firebaseAuth(myDataRef);

refObj.$createUser({
    email: $scope.emailId,
    password: $scope.password
}).then(function(userData) {
    var UserUniqueUrl = new Firebase(baseURL + 'users/' + userData.uid + '/');
    UserUniqueUrl.set({
        'email': $scope.emailId,
        'username': $scope.username,
        'uid': userData.uid,
        'theme': 'default'
    }, function(error) {
        if (error) {
            console.log(error);
        } else {
            console.log('Successfully updated in user table');
        }
    });
}).catch(function(error) {
    if (error.code == 'EMAIL_TAKEN') {
        $scope.regStatusError = 'Email already registered!';
    } else {
        $scope.regStatusError = 'Unable to register! Try again later.';
    }
});
这是我的安全规则

{
    "rules": {
        "users": {
            ".read": "auth != null",
            ".write": "auth != null"
        }
    }
}
现在,如果我尝试注册它,它会给我权限被拒绝的错误,我确信这是因为安全规则
。读:“auth!=null”
。写:“auth!=null”
。如果我将规则更改为
“.read”:true
”.write:true
,则注册将有效,但任何人都可以看到我的用户数据,包括uid和电子邮件id,这是我不希望看到的。我如何更改规则以满足我的需要

这就是我的用户表的外观 感谢您的帮助。
谢谢。

是的,你需要把规则改成这样

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}

这应该可以修复它

您只需要在firestore数据库中创建经过身份验证的用户:

match /users/{uid} {
          allow create: if request.auth.uid != null;
} 
但是,您可以通过以下方式验证用户的电子邮件:

match /users/{uid} {
          allow create: if request.auth.uid != null
              && request.auth.token.email_verified == true
}

请注意,uid将与文档的ID匹配。

$createUser()
不受安全规则的影响。控制台中出现了什么错误?
$createUser
由于其他原因失败,或者
set()
失败。
set()
失败。它给出了权限被拒绝的错误。很明显,它失败了,因为我已经将user table设置为
。.read:“auth!=null”
。我只是需要一个办法。安全规则有什么关系?如图所示,您的代码没有进行任何读取。我已设置了
”。write:“auth!=null”
。我在问题中已经提到了这一点。