且构网

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

firebase 云函数身份验证:onCreate 事件不包含 displayName

更新时间:2023-12-03 09:41:34

当您在 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
  // ...
}

您的 Cloud Functions 功能是通过以下精确信息触发的:只需电子邮件和密码.

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 函数.
  • 将整个用户创建交给 Cloud Functions,将电子邮件+密码+显示名称传递给您的自定义函数,然后创建用户帐户,设置其显示名称,并为该用户创建文档.