Should firebase auth onCreate trigger have more data?

血红的双手。 提交于 2021-02-05 08:19:28

问题


I'm using functions.auth.user().onCreate() as part of a firestore project, and trying to set up some default data when a new user registers. For the front end, I'm using firebase-ui, with Google and Email/Password providers enabled.

When I sign in with an email and password, the UI widget prompts to enter a name and set a password. I was expecting to see the name as part of the user parameter in the onCreate() function call, but I'm getting practically nothing:

user: { email: 'xxx@yyyy.co.uk',
  emailVerified: false,
  displayName: null,
  photoURL: null,
  phoneNumber: null,
  disabled: false,
  providerData: [],
  customClaims: {},
  passwordSalt: null,
  passwordHash: null,
  tokensValidAfterTime: null,
  metadata: 
   UserRecordMetadata {
     creationTime: '2018-11-20T15:06:01Z',
     lastSignInTime: '2018-11-20T15:06:01Z' },
  uid: 'QDJ5OJTwbvNo2QNDVQV9VsxC2pz2',
  toJSON: [Function] }

Not even getting the provider info so I can tell which 'kind' of user registered. It's almost like this function is triggered before the user record has been populated (except the email address does get through). Also, registrations via the Google provider come with a fully-populated user record, so I guess this is a problem with Email/Password specifically.

Is this a bug, or am I missing something? I didn't see anything else useful in the context parameter either.


回答1:


The fact that displayName is not populated in the Cloud Functions onCreate trigger for email+password is expected. The function is triggered from the first API call (createUserWithEmailAndPassword()), while the display name is set with a second API call (updateProfile).

The usual workaround would be to create a Cloud Function to update the user profile, as shown here: Firebase Auth+Functions | create user with displayName

I also highly recommend filing a feature request to be able to have a Cloud Function triggered on profile changes.



来源:https://stackoverflow.com/questions/53396227/should-firebase-auth-oncreate-trigger-have-more-data

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