我瀏覽了很多帖子,但仍然無法解決這個問題。當我嘗試更新用戶的個人資料時,我得到了未兌現的承諾。
以下是我當前的功能。請幫忙謝謝!
const createUser = async () => {
await addDoc(database.usersRef, {
email: emailRef.current.value,
fullName: nameRef.current.value,
mobileNumber: mobileRef.current.value,
status: "Active",
userType: userTypeRef.current.value
});
};
async function handleSubmit(e) {
e.preventDefault()
counter ;
const password = "Password1!"
const secondaryApp = firebase.initializeApp({
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN
}, '' counter)
const newAuth = getAuth(secondaryApp);
try {
setError('');
setLoading(true);
const newUser = await createUserWithEmailAndPassword(newAuth, emailRef.current.value, password)
updateProfile(newAuth.currentUser, {
displayName: nameRef.current.value,
phoneNumber: mobileRef.current.value
}).catch((error) => {
console.log(error);
})
await sendEmailVerification(newUser.user);
newAuth.signOut();
createUser();
setShowModal(true);
} catch (e) {
console.log(e)
setError('Failed to create an account')
}
setLoading(false)
}

uj5u.com熱心網友回復:
最好不要將async/ await/catch與then()/混合catch()使用,而是使用其中一種。
由于您正在使用try/ catch,因此也可以await在呼叫時使用updateProfile,以便將任何錯誤轉換為例外
try {
setError('');
setLoading(true);
const newUser = await createUserWithEmailAndPassword(newAuth, emailRef.current.value, password)
// ??
await updateProfile(newAuth.currentUser, {
displayName: nameRef.current.value,
phoneNumber: mobileRef.current.value
})
await sendEmailVerification(newUser.user);
newAuth.signOut();
createUser();
setShowModal(true);
} catch (e) {
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/453339.html
標籤:节点.js 反应 火力基地 firebase 身份验证
