Skip to content

displayName not set when creating new email account #1574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ambrice opened this issue Jan 23, 2019 · 3 comments
Closed

displayName not set when creating new email account #1574

ambrice opened this issue Jan 23, 2019 · 3 comments

Comments

@ambrice
Copy link

ambrice commented Jan 23, 2019

I have the following function for updating firebase database user entry when a new user is created:

exports.addUserData = functions.auth.user().onCreate((user) => {
    console.log("Adding new user " + user.uid);
    return admin.auth().getUser(user.uid).then(userRecord => {
        var userData = admin.database().ref('/users').child(user.uid);
        userData.child('name').set(userRecord.displayName);
        userData.child('email').set(userRecord.email);
        userData.child('is_admin').set(false);
        admin.database().ref('/users_idx').child(md5(userRecord.email)).set(userData.key);
    });
});

When creating a new email account from the firebase-ui web library, this function triggers correctly. When using firebase-ui android library 4.2.1, the userRecord.displayName is undefined even though a full name was entered.

@samtstern
Copy link
Contributor

samtstern commented Jan 23, 2019

For FirebaseUI android this is expected behavior. Behind the scenes we do two operations:

  1. Create user with email/password
  2. Immediately update the display name

It's operation (1) that triggers the cloud function, since that's when the user is created. What I don't understand is how firebaseui-web is getting around this issue. @bojeil-google any idea?

@ambrice
Copy link
Author

ambrice commented Jan 23, 2019

That was originally an issue, but I worked around that in the function by calling getUser() instead of using the user that was passed into the trigger. I don't know why that works when the user is created from the web library but not the android library.

@samtstern
Copy link
Contributor

@ambrice in that case it's just a race condition. If your getUser request happens before we update the display name, then you will not see a name in your cloud function. It's possible that FirebaseUI on the web is just faster, but that's not behavior you should rely on.

Since there's nothing I can do here to make this work every time, I am going to close the issue. I know it sounds like a terrible solution but you could try adding a ~5second delay within your function before fetching the user record to make the race condition less likely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants