1 回答
TA貢獻1777條經驗 獲得超3個贊
這是因為該updateProfile()方法是異步的,不會觸發通過 設置的監聽器onAuthStateChanged()。
因此,當onAuthStateChanged()在創建用戶(并登錄,因為在創建用戶帳戶之后,用戶也已登錄)后立即觸發偵聽器時, 的值尚未更新displayName。
當方法返回的承諾updateProfile()得到解決時,您可能應該更新 Vuex Store 中的狀態。
以下幾行:
?firebase
? ? .auth()
? ? .createUserWithEmailAndPassword(this.user.email, this.user.password)
? ? .then((res) => {
? ? ? return res.user.updateProfile({
? ? ? ? displayName: this.user.username,
? ? ? });
? ? })
? ? .then(() => {
? ? ? //Update the Vuex Store here with firebase.auth().currentUser
? ? ? console.log(firebase.auth().currentUser.displayName);
? ? })
? ? .catch((error) => {
? ? ? this.error = error.message;
? ? ? console.log('err', error);
? ? });
添加回答
舉報
