我正在尝试在Firebase中创建用户,但出现以下错误:TypeError: Can not read property 'uid' of undefined
。
换句话说,如果您创建用户但不写文档。
interface User {
uid: string;
email: string;
photoURL?: string;
displayName?: string;
favoriteColor?: string;
fechaRegistro?: string;
}
emailSignUp(email: string, password: string, displayName: string ) {
this._displayName = displayName;
return this.afAuth.auth
.createUserWithEmailAndPassword(email, password)
.then(credential => {
this.pushUserDataEmail(credential.user);
console.log('Usuario creado')
this.router.navigate(['/userProfile'])
})
.catch(error => {
this.handleError(error)
});
}
private pushUserDataEmail( user: User ) {
const userRef: AngularFirestoreDocument<User> = this.afs.doc(`users/${user.uid}`);
const data: User = {
uid: user.uid,
email: user.email,
displayName: this._displayName
};
userRef.set(data, {merge: true});
}
但是,当我在另一个应用程序中尝试相同的代码时,它可以正常工作,即先创建用户,然后编写文档。