Firebase - no displayName for user

前端 未结 2 772
野的像风
野的像风 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

    0 讨论(0)
  • 2021-02-15 13:13

    I guess if you just want to update users profile:

    firebase.auth().onAuthStateChanged(function(user) {
      if (user) {
        // User is signed in.
        user.updateProfile({
            displayName: "Random Name"
        }).then(function() {
            // Update successful.
        }, function(error) {
            // An error happened.
        });
    
      } else {
        // No user is signed in.
      }
    });
    

    Additionally: https://firebase.google.com/docs/auth/web/manage-users

    0 讨论(0)
提交回复
热议问题