So I am trying to save user data from firebase into firestore and I keep getting this error
DocumentReference.set() called with invalid data. Unsupported field
value: undefined (found in field uid)
Here are the 2 methods involved:
register(credentials) {
return this.afAuth.auth.createUserWithEmailAndPassword(credentials.email, credentials.password).then(user => {
return this.setUserDoc(user);
}).catch(error => console.log(error.message));
}
private setUserDoc(user) {
console.log(user);
const userRef: AngularFirestoreDocument<User> = this.afs.doc(`users/${user.uid}`);
const data: User = {
uid: user.uid, <-- says this is undefined
email: user.email
}
return userRef.set(data);
}
If I console.log(user) that is passed into the setUserDoc method I can open it and it has a uid but if I console.log(user.uid) it says undefined. Can someone help me figure out why this is happening?