gpt4 book ai didi

javascript - Firebase 用户 PERMISSION_DENIED : Permission denied

转载 作者:行者123 更新时间:2023-11-30 09:36:19 25 4
gpt4 key购买 nike

我正在使用 firebase 身份验证,我引用了这个 link

"users": {
".read": "auth != null && root.child('admins').child(auth.uid).val() == true",
".write": "auth != null && (root.child('admins').child(auth.uid).val() == true)",
"$uid": {
".read": "auth != null && (auth.uid == $uid || root.child('admins').child(auth.uid).val() == true)",
".write": "auth != null && (auth.uid == $uid || root.child('admins').child(auth.uid).val() == true)"
}
},

这是我的 firebase 用户表规则。

我的服务.js

signupUser: function(newUser) {
var secondaryApp = firebase.initializeApp(FirebaseAppConfig, "Secondary");
var usersRef = firebase.database().ref().child('users');
return secondaryApp.auth()
.createUserWithEmailAndPassword(newUser.email, newUser.password)
.then(function(firebaseUser) {
secondaryApp.auth().signOut();

var newUserWithoutPwd = _.extend({}, newUser);
delete newUserWithoutPwd.password;
return usersRef
.child(firebaseUser.uid)
.set(newUserWithoutPwd)
.then(function() {
return newUserWithoutPwd;
});
});
},

认证成功。但是用户表显示权限被拒绝错误。

显示下面的屏幕截图

enter image description here

最佳答案

我的猜测是您希望新创建的用户将他们的用户配置文件写入数据库。在这种情况下,重要的是:

  1. 您将配置文件数据作为当前用户编写:firebase.database(secondaryApp).ref().child('users')
  2. 在写入完成之前不要注销用户

在代码中:

signupUser: function(newUser) {
var secondaryApp = firebase.initializeApp(FirebaseAppConfig, "Secondary");
var usersRef = secondaryApp.database().ref().child('users');
return secondaryApp.auth()
.createUserWithEmailAndPassword(newUser.email, newUser.password)
.then(function(firebaseUser) {
var newUserWithoutPwd = _.extend({}, newUser);
delete newUserWithoutPwd.password;
return usersRef
.child(firebaseUser.uid)
.set(newUserWithoutPwd)
.then(function() {
secondaryApp.auth().signOut();
return newUserWithoutPwd;
});
});
},

关于javascript - Firebase 用户 PERMISSION_DENIED : Permission denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43366061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com