I'm new firebase database, I try to update UID to Realtime Database when signup, but got an error like this
Error: Reference.update failed: First argument contains undefined in property 'users.UID.email'
auth.service.ts
import ...
...
export class AuthService {
...
async emailSignUp(email: string, password: string) {
try {
const user = await this.afAuth.auth.createUserWithEmailAndPassword(email, password);
console.log('user ', user);
this.authState = user;
console.log('authState ', this.authState);
this.updateUserData();
this.router.navigate(['/']);
} catch (error) {
return console.log(error);
}
}
get currentUserId(): string {
console.log('currentId ', this.authenticated, ' ', this.authState.user.uid);
return this.authenticated ? this.authState.user.uid : '';
}
private updateUserData(): void {
const path = `users/${this.currentUserId}`; // Endpoint on firebase
const userRef: AngularFireObject<any> = this.db.object(path);
const data = {
email: this.authState.email,
name: this.authState.displayName
};
userRef.update(data)
.catch(error => console.log(error));
}
}
Can somebody help me, please? please let me know if more snippets are needed. Thanks in advance.
