我试图保存我的用户已登录的事实,然后将其重定向到他的管理页面上但是当我使用await时出现此错误:
等待是保留字(101)
另一件事,一旦我的用户注册,我想将他发送到一个新页面,而不是一个"幻灯片页面"我们可以用右上角的箭头返回。 我怎么能这样做?
这是我的代码:
login(){
firebase.auth().signInWithEmailAndPassword(this.state.emailLogin,
this.state.passwordLogin).then((user) => {
// Send the user to the next step
try {
await AsyncStorage.setItem('@MySuperStore:key', 'I like
to save it.');
} catch (error) {
// Error saving data
}
const { navigate } = this.props.navigation;
navigate('Admin');
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === 'auth/wrong-password') {
alert('Wrong password.');
} else {
alert(errorMessage);
}
console.log(error);
});
}
提前感谢您的帮助。
答案 0 :(得分:8)
在函数中使用await
时,必须将其标记为async
this.state.passwordLogin).then( aysnc (user) => {
...
})