我正在嘗試運行兩個異步函式,但是我不斷收到以下錯誤。
錯誤:未處理的承諾拒絕:RangeError:超出最大呼叫堆疊大小。
有人可以幫忙嗎。我需要更新顯示名稱、電子郵件和密碼,并且在我的 useAuth.js 中的不同功能中需要它們。我只在嘗試運行超過 1 個函式時收到錯誤
profile.js
//context
const {
updateDisplayName,
updateEmail,
updatePassword,
} = useAuth();
// when update button is pressed this function runs
const handleSubmit = async (event) => {
// prevent page from reloading
event.preventDefault();
// make sure there no old error before making new request
setErrorUpdating([]);
await updateDisplayName(displayName)
await updateEmail(email);
await updatePassword(password)
}
使用Auth.js
async function updateDisplayName(displayName) {
const updateDisplayName = await updateProfile(currentUser, { displayName });
// update the ui with the updated profile
const newUserObj = { ...currentUser, displayName };
setCurrentUser(newUserObj);
return updateDisplayName;
}
async function updateEmail(email) {
return await updateEmail(currentUser, email);
}
async function updatePassword(password) {
return await updatePassword(currentUser, password);
}
uj5u.com熱心網友回復:
這兩個方法呼叫無限地呼叫自己:
async function updateEmail(email) {
return await updateEmail(currentUser, email);
}
async function updatePassword(password) {
return await updatePassword(currentUser, password);
}
請注意,您的自定義updateEmail呼叫了自己,就像updatePassword. 您可能正在嘗試在那里呼叫 Firebase 等效項,但您的自定義函式正在影響 Firebase 匯入。
您可以重命名自定義函式,以免與 Firebase 名稱發生沖突:
async function updateEmailForCurrentUser(email) {
return await updateEmail(currentUser, email);
}
async function updatePasswordForCurrentUser(password) {
return await updatePassword(currentUser, password);
}
然后呼叫它handleSubmit:
const handleSubmit = async (event) => {
...
await updateEmailForCurrentUser(email); // ??
await updatePasswordForCurrentUser(password); // ??
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/476157.html
標籤:javascript 反应 firebase 身份验证
