2

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?

1 Answer 1

1

Okay I figured it out. I was just one level too high. if I changed the call to pass credential.user it worked. So now the code is:

register(credentials) {
    return this.afAuth.auth.createUserWithEmailAndPassword(credentials.email, credentials.password).then(credential => {
      return this.setUserDoc(credential.user); <-- changed what was passed
    }).catch(error => alert(error.message));
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.