jeffminsungkim / Ashy

0 stars 0 forks source link

Create a simple page which updates user profile #27

Closed jeffminsungkim closed 6 years ago

jeffminsungkim commented 6 years ago

Objective Create a page where users can update their profile picture and select the display name.

When the user account created through email and password, there's no way to get user's displayName to populate into a database.

It is very dangerous to maintain the following code below because it does not work consistently.

return new Promise((resolve, reject) => {
  this.afAuth.auth.currentUser.updateProfile({
              displayName: user.displayName,
              photoURL: this.defaultProfileImgURL
            }).then(() => {
              this.usersRef.doc(auth.uid).update({
                displayName: user.displayName
              }).then(() => resolve());

See the API doc createUserWithEmailAndPassword.

On the client, Firebase UI Web then updates the profile of the user using a subsequent updateProfile method. I cannot notice this from your web app because Firebase UI resorts to a "trick" to only fire the onAuthStateChanged of your FirebaseApp instance listener after the profile of the user has updated.

Technically: Firebase UI does the account creation and profile update in a separate Firebase App instance, then, when the user is fully ready it signs-the user in your original FirebaseApp instance.

However, on Cloud Function, the trigger will get called right after the createUserWithEmailAndPassword call, before the profile is updated.