title: FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined (found in field nombre)
body: <p>Following code works to create a new user in Firebase but It gives below error in browser, Could you help me to understand why?</p>
  
  <blockquote>
    <p>Function DocumentReference.set() called with invalid data. Unsupported field value: undefined (found in field nombre)</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/Ms23P.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ms23P.png" alt="r"></a></p>
  
  <p>Code:</p>
  
  <pre><code>export class AuthService {
  
    private userSubscription: Subscription = new Subscription();
  
    constructor(private afAuth: AngularFireAuth,
      private router: Router,
      private afDB: AngularFirestore,
      private store: Store&lt;AppState&gt;) { }
  
  initAuthListener() {
  
      this.afAuth.authState.subscribe((fbUser: firebase.User) =&gt; {
        if (fbUser) {
          this.userSubscription = this.afDB.doc(`${fbUser.uid}/usuario`).valueChanges()
            .subscribe((usuarioObj: any) =&gt; {
  
              const newUser = new User(usuarioObj)
  
              this.store.dispatch(new SetUserAction(newUser))
  
            })
        } else {
          this.userSubscription.unsubscribe()
        }
      })
    }
  
    createUser(nombre: string, email: string, password: string) {
  
      this.store.dispatch(new ActivarLoadingAction())
  
      this.afAuth.auth
        .createUserWithEmailAndPassword(email, password)
        .then(resp =&gt; {
  
  
          const user: User = {
            uid: resp.user.uid,
            nombre: nombre,
            email: resp.user.email
          }
  
          this.afDB.doc(`${user.uid}/usuario`)
            .set(user)
            .then(() =&gt; {
  
              this.router.navigate(['/'])
              this.store.dispatch(new DesactivarLoadingAction())
            })
  
  
        })
        .catch(erro =&gt; {
          console.error(erro)
          this.store.dispatch(new DesactivarLoadingAction())
          Swal.fire('Error!', erro.message, 'error')
        })
    }
  
  
  }
  
  </code></pre>