Firebase - no displayName for user

爱⌒轻易说出口 提交于 2019-12-12 08:43:05

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/38227139/firebase-no-displayname-for-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!