1
我完全意識到在註冊後立即觸發了AuthStateChange函數,但事實並非如此。在用戶使用其用戶名和密碼登錄後,我遇到此功能的兩次問題。第一次啓動時,我追溯到堆棧,它來自我的代碼,但第二次來自Firebase JS文件本身。我很困惑,因爲我不明白他們爲什麼會起火。我正在使用網絡版的Firebase。代碼在下面提供。Firebase onAuthStateChange在登錄時觸發兩次
TL; DR:我正在使用Web版的Firebase。在用戶使用其用戶名和密碼登錄後,onAuthStateChange函數會觸發兩次。
// callback function
firebase.auth().onAuthStateChanged(function(user) {
console.log("change");
if (authCounter == 0) {
authCounter = 1;
} else {
if (user) {
currentUser = user.uid;
dbRef = firebase.database().ref().child(currentUser);
handleEvent(9);
} else {
handleEvent(10);
}
}
});
// sign in function
firebase.auth().signInWithEmailAndPassword(email, pass).catch(function(error) {
displayError(error.code);
});