[英]Didn't rerender? Firebase and React-Native login after signup
拋出此錯誤:
there is no user record corresponding to this identifier
從這段代碼:
const createAccount = () => {
if (password === passwordTwo) {
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function (error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
alert(errorMessage)
}).then(
firebase.auth().signInWithEmailAndPassword(email, password)
.then(navigation.navigate('homeDashboard', { userEmail }))
);
} else {
alert('passwords dont match')
}
}
我知道這與在調用“then”之前未更新數據庫有關,我嘗試執行 await function 但無法正常工作,如果我重新呈現主頁(nav 指向的位置)它是更新了路線信息,所以我知道它是否有效只是沒有重新渲染或其他什么? 有什么好的解決辦法嗎?
你的 then() 方法讓我望而卻步。 好像他們缺少回調。
then()方法返回一個Promise。它最多需要兩個arguments:Promise的成功和失敗情況的回調函數。
我將您的 function 重寫為以下內容並進行了測試。
const createAccount = () => {
if (password === passwordTwo) {
firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.catch(function (error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
alert(errorMessage);
})
.then(() => {
firebase
.auth()
.signInWithEmailAndPassword(email, password)
.then((res) => {
console.log('res.user.uid', res.user.uid);
// Here you would generally like to do something with the user id
// maybe put it in the store, so you can use it in your homeDashBoard
// or in other parts of your application were the user is logged in.
navigation.navigate('homeDashboard', { userEmail });
});
});
} else {
alert('passwords dont match');
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.