如何转换此代码(Promise):
registerUser(formData) {
firebase.auth().createUserWithEmailAndPassword(formData.email,formData.passwords.password)
.then((user) => {
firebase.database().ref(`/users/${user.uid}`).set({
id: user.uid,
email: formData.email
})
this.routing.navigate(['/login']);
}).catch((error) => {
console.log(error);
})
}
进入这个(async / await):
async registerUser(formData){
try{
await firebase.auth().createUserWithEmailAndPassword(formData.email,formData.passwords.password);
firebase.database().ref(`/users/${user.uid}`)
.set({id: user.uid,email: formData.email});
this.routing.navigate(['/login']);
return true;
}catch(error){
return false;
}
}
如何获取user.uid
(注册用户uid)?在promises中它很容易,因为我只需要传递参数(用户)。
谢谢,求助:)
答案 0 :(得分:4)
如何获得
Running setup.py install for scipy ...
...
user.uid
表达式返回 user
,因此请在其前面添加await
(或let user =
):
const user =