Skip to content
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

The UserRecord object is missing displayName when signing in with firebase-ui #530

Closed
salah3x opened this issue Jul 17, 2019 · 4 comments
Closed
Assignees

Comments

@salah3x
Copy link

salah3x commented Jul 17, 2019

Related issues

[REQUIRED] Version info

node:
v10.15.3

firebase-functions:
3.1.0
firebase-tools:
7.1.0

firebase-admin:
8.0.0

[REQUIRED] Test case

The UserRecord object doesn't have all the properties.
I'm interrested in photoUrl & displayName but they are null.
Other properties like uid, email, and creationTime are set to the correct values

[REQUIRED] Steps to reproduce

export const AddUser = functions.auth.user().onCreate( (user: functions.auth.UserRecord, ctx: functions.EventContext) => {
      console.log(user);
}

when I sign in using firebase-ui (username+password) I got the following output in cloud functions' logs

2019-07-17T22:52:37.155292717Z D AddUser: Function execution started
2019-07-17T22:52:40.141Z ? AddUser: { email: '[EMAIL]',
2019-07-17T22:52:40.141Z ? AddUser:   emailVerified: false,
2019-07-17T22:52:40.141Z ? AddUser:   displayName: null,
2019-07-17T22:52:40.141Z ? AddUser:   photoURL: null,
2019-07-17T22:52:40.141Z ? AddUser:   phoneNumber: null,
2019-07-17T22:52:40.141Z ? AddUser:   disabled: false,
2019-07-17T22:52:40.141Z ? AddUser:   providerData:
2019-07-17T22:52:40.141Z ? AddUser:    [ { email: '[EMAIL]',
2019-07-17T22:52:40.141Z ? AddUser:        providerId: 'password',
2019-07-17T22:52:40.141Z ? AddUser:        uid: '[EMAIL]',
2019-07-17T22:52:40.141Z ? AddUser:        toJSON: [Function] } ],
2019-07-17T22:52:40.141Z ? AddUser:   customClaims: {},
2019-07-17T22:52:40.141Z ? AddUser:   passwordSalt: null,
2019-07-17T22:52:40.141Z ? AddUser:   passwordHash: null,
2019-07-17T22:52:40.141Z ? AddUser:   tokensValidAfterTime: null,
2019-07-17T22:52:40.141Z ? AddUser:   metadata:
2019-07-17T22:52:40.141Z ? AddUser:    UserRecordMetadata {
2019-07-17T22:52:40.141Z ? AddUser:      creationTime: '2019-07-17T22:52:36Z',
2019-07-17T22:52:40.141Z ? AddUser:      lastSignInTime: '2019-07-17T22:52:36Z' },
2019-07-17T22:52:40.141Z ? AddUser:   uid: '[UID]',
2019-07-17T22:52:40.141Z ? AddUser:   toJSON: [Function] }
2019-07-17T22:52:40.343503821Z D AddUser: Function execution took 3189 ms, finished with status: 'ok'

[REQUIRED] Expected behavior

To get the full user object.
BTW: The field are present when I get the user object using the client SDK or when I sign in using Google oauth, no problems there!

[REQUIRED] Actual behavior

The UserRecord object is missing the photoUrl & displayName fields, maybe other fields too.

Were you able to successfully deploy your functions?

Yep.

@kevinajian
Copy link
Contributor

Hi @salah3x,

I think the issue is that when you register an email/password user, there is usually no displayName or photoUrl associated with that account yet. When you go through the other examples you mention such as Google OAuth, your Google account already has those details linked, so they are returned properly.

Here's an example where I first register as an email/password user:
image
Then, when I link it to my Google account through FirebaseUI, those missing fields are then filled out:
image

Let me know if I'm mistaken, but in this case the function is returning all of the information that it has available at the time. You can find more information about this on our User properties doc. Hope that helps.

@salah3x
Copy link
Author

salah3x commented Jul 26, 2019

You are correct about the photoUrl being set to null, but I set the requireDisplayName to true when setting up firebase-ui, so I can enter a name in the UI and it gets added to the firebase user object:

Capture

It just doesn't show up in the onCreate() function.

@kevinajian
Copy link
Contributor

Ah I was missing the requireDisplayName. Looking into this more, it seems like this is happening because the email password creation and setting the display name are happening in two different calls in FirebaseUI. As a result, when onCreate() gets called, only the email and password is known at that time and gets passed along.

This does seem specific to FirebaseUI, so you might be able to work around this similar to this example. There are also more details in this thread.

I would recommend filing a feature request to bring more attention to this issue. Hope this helps.

@salah3x salah3x changed the title The UserRecord object is missing some information The UserRecord object is missing displayName when signing in with firebase-ui Jul 26, 2019
@salah3x
Copy link
Author

salah3x commented Jul 26, 2019

Thanks @kevinajian

So here is a summary of this issue (for people facing similar issue):

  • The signInWithEmail API call (unlike OAuth) doesn't accept displayName.
  • So Firebase-ui makes a second call to update the profile before signing in the user.
  • Unfortunately, the cloud function onCreate() gets triggered upon the first call (no displayName)

Based on this discussion:

  • 1st workaround:
    export const AddUser = functions.auth
      .user()
      .onCreate(
        async (user: functions.auth.UserRecord, ctx: functions.EventContext) => {
        const myUser = await admin.auth().getUser(user.uid);
      }
    );
    
    thought this is not guarateed to work.
  • 2nd workaround:
    In the client side, and when getting the user from firestore, verify if the displayName is not undefined, and if it is, then set it the current logged in user's displayName.

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

No branches or pull requests

3 participants