Firebaseui-web: firebase create user by email not returning displayName using ui 2.3.0

Created on 28 Jul 2017  路  6Comments  路  Source: firebase/firebaseui-web

seeing this issue closed several times in here, I am little shocked I have to post this issue.

using a simple firebase function, and using code very similar to the example here: https://firebase.google.com/docs/reference/functions/functions.auth.UserBuilder#onCreate

and using the sign in by email method on the firebase ui, and having the user sign up with first and last name,

my firebase function:

exports.createAccount = functions.auth.user().onCreate(function(event) {
    const data = event.data;
    console.log(data);
});

and the firebase function log shows me:

{ email: '[email protected]',
  metadata: 
   { createdAt: 2017-07-28T14:29:08.000Z,
     lastSignedInAt: 2017-07-28T14:29:08.000Z },
  uid: 'xxxxxxxxxxx' }

where is yoda's displayName (should be: Yoda Yo) which he entered in firebase ui?

And, so if I used the entire example in the link I posted above, how am I supposed to send yoda a personalized sign up email using his first name, when firebase ui doesn't even return it?

Most helpful comment

I have a functional setup using a delay, but it does create a race condition. It seems a nicer solution would be to add an onUpdate trigger on the UserBuilder object (maybe this is already on a todo list somewhere?).

functions.auth.user().onUpdate(...)

All 6 comments

The Firebase function onCreate triggers immediately after the user is created. For an email/password, this is the createUserWithEmailAndPassword. We then call a separate API to updateProfile with the user's display name. By the time you get the event triggered (at createUserWithEmailAndPassword), the display name has not been set yet.

okay then. thanks for this new info.

how about somewhere, the firebase team mention in ui or user creation documentation that email sign up does not act as expected or the same as other provider sign up. or fix it so they all work the same, ie don't return a user until all profile info like displayName is ready.

in the meantime - any suggestion HOW to actually get the user displayName upon creation from email sign up using ui?

Update:
nevermind, able to pull user info with a promise after email signup:

exports.createAccount = functions.auth.user().onCreate(function(event) {
    const data = event.data;
    console.log(data);
    admin.auth().getUser(data.uid)
  .then(function(userRecord) {
    console.log("Successfully fetched user data:", userRecord.toJSON());
  })
  .catch(function(error) {
    console.log("Error fetching user data:", error);
  });
});

functions console shows displayName:

Successfully fetched user data: { uid: 'xxxxxxxx',
  email: '[email protected]',
  emailVerified: false,
  displayName: 'yoda yo',
  photoURL: undefined,
  disabled: false,
  metadata: 
   { lastSignedInAt: 2017-07-29T12:50:54.000Z,
     createdAt: 2017-07-29T12:50:54.000Z },
  providerData: 
   [ { uid: '[email protected]',
       displayName: 'yoda yo',
       email: '[email protected]',
       photoURL: undefined,
       providerId: 'password' } ] }

By the time the getUser Admin request resolves, the client updateProfile operation must have resolved. You could always add some short delay (in milliseconds) to make sure updateProfile has time to resolve.

Typically when you sign in with all federated providers (Google, Facebook, Twitter, GitHub), the display name is immediately populated and the displayName immediately available onCreate.
For password sign up, the displayName is not always required. Many developers don't even want to force users to provide their name on password sign up. FirebaseUI makes it an optional field (after many developers requested that).

You can always add an HTTP endpoint with Firebase Functions after the sign-up operation resolves and send the ID token along to send the welcome email. You have a lot of options.

I have a functional setup using a delay, but it does create a race condition. It seems a nicer solution would be to add an onUpdate trigger on the UserBuilder object (maybe this is already on a todo list somewhere?).

functions.auth.user().onUpdate(...)

onUpdate on auth is vital.

I actually don't understand how there's no way to make this flow the same across providers. Also, no idea why this issue is closed. @bojeil-google saying "You have a lot of options" is a weird response. IMO this is a bug, that there's no way to handle it nicely. Adding a delay to code specifically to handle this is horrible :/

@Dayjo a bit late I know :P ..
I think that the idea is that you first do a auth then fetch the user data.. Perhaps not Ideal in most cases but still..

I guess that my recommendation would be to use some kind of store (like ngrx store, redux or ngxs) and set ut a observer on the Auth object as the recommend here: https://firebase.google.com/docs/auth/web/manage-users#get_the_currently_signed-in_user

Was this page helpful?
0 / 5 - 0 ratings