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