Skip to content Skip to sidebar Skip to footer

Firebase Cloud Function Authentication: Oncreate Event Doesn't Contain Displayname

I have a cloud function for onCreate that looks like exports.addNewUserToCollection = functions.auth.user().onCreate(event => { const user = event.data; // The Firebase user

Solution 1:

When you create an email+password account in Firebase Authentication, you specify only the minimum information: email and password. For example on iOS this is:

Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
  // ...
}

Your Cloud Function is triggered with this precise information: just the email and password.

While it is possible to later update the user profile to include the display name, that information is not passed on to the Cloud Function trigger (which currently only triggers on account creation).

Possible workaround are:

  • Call a Cloud Function from your code, when you update the user profile to set the display name.
  • Hand the entire user creation of to Cloud Functions, passing email+password+displayName into your custom function, which then creates the user account, sets their display name, and creates the document for that user.

Post a Comment for "Firebase Cloud Function Authentication: Oncreate Event Doesn't Contain Displayname"