1

现在用火力认证,我是指这个link火力地堡用户PERMISSION_DENIED:权限被拒绝

"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)" 
     } 
     }, 

这是我的火力用户表的规则。

我services.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; 
      }); 
      }); 
     }, 

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

显示屏幕下方打出

enter image description here

+0

基于你怎么想的是,用户有权写? –

回答

1
  1. 删除secondaryApp.auth().signOut();
  2. 更新此return firebase.database(secondaryApp).ref().child('users')

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

我的猜测是,你要新创建的用户编写自己的用户档案数据库。在这种情况下,重要的是:

  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; 
      }); 
     }); 
    }, 
+0

谢谢。这更好。 – TAM

相关问题