Having recently started to use the Firebase database, I encountered an issue while trying to update the UID to the Realtime Database during signup. The error message displayed was:
Error: Reference.update failed: First argument contains undefined in property 'users.UID.email'
This occurred in auth.service.ts file, as shown below:
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));
}
}
Console https://i.sstatic.net/812ZW.png
If anyone could provide assistance, it would be greatly appreciated. Feel free to request additional code snippets if necessary. Thank you in advance.