Firebase - no displayName for user

前端 未结 2 767
野的像风
野的像风 2021-02-15 12:24

I can add users in Firebase console -> Auth but I can\'t do anything more than setting an email and password for them.

Could I in some way set for them displayName?

2条回答
  •  深忆病人
    2021-02-15 13:05

    When you create a user you create it only with email and password but you can and the displayName in the promise, then inside the .then() method you call the updateProfile method and you are ready, right down is the code:

      onSubmit(formData) {
        if(formData.valid) {
          console.log(formData.value);
          this.af.auth.createUserWithEmailAndPassword(
            formData.value.email,
            formData.value.password
          ).then(
            (success) => {
             console.log(success); 
            success.updateProfile({
              displayName: "Example User",
              photoURL: "https://example.com/jane-q-user/profile.jpg"
            }).catch(
            (err) => {
            this.error = err;
            });        
            this.router.navigate(['/login'])
          }).catch(
            (err) => {
            this.error = err;
          })
        }
      }
    

    Note that in my example the displayName is set to "Example User", in the real app you just add the parameter as in my case it should be -> displayName:formData.value.name

提交回复
热议问题