且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Firebase云功能身份验证:onCreate事件不包含displayName

更新时间:2023-12-03 09:59:10

在Firebase身份验证中创建电子邮件+密码帐户时,您仅指定最低限度的信息:电子邮件和密码.例如,在iOS上是:

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.

虽然以后可以更新用户配置文件以包括显示名称,但是该信息不会传递到Cloud Function触发器(当前仅在创建帐户时触发).

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).

可能的解决方法是:

  • 更新用户个人资料以设置显示名称时,请从代码中调用Cloud Function.
  • 将整个用户创建交给Cloud Functions,然后将email + password + displayName传递到您的自定义函数中,然后再创建用户帐户,设置其显示名称并为该用户创建文档.