firebase auth onCreate 触发器应该有更多数据吗? [英] Should firebase auth onCreate trigger have more data?

查看:16
本文介绍了firebase auth onCreate 触发器应该有更多数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 functions.auth.user().onCreate() 作为 Firestore 项目的一部分,并尝试在新用户注册时设置一些默认数据.对于前端,我使用的是 firebase-ui,启用了 Google 和电子邮件/密码提供程序.

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.

当我使用电子邮件和密码登录时,UI 小部件会提示输入名称并设置密码.我希望在 onCreate() 函数调用中将名称作为 user 参数的一部分,但实际上我什么也没得到:

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] }

甚至没有获得提供商信息,因此我可以知道注册了哪种类型"的用户.几乎就像在填充用户记录之前触发了此功能(除了电子邮件地址确实通过).此外,通过 Google 提供商进行的注册带有完整填充的 user 记录,所以我想这特别是电子邮件/密码的问题.

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.

这是一个错误,还是我遗漏了什么?我也没有在 context 参数中看到任何其他有用的东西.

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

推荐答案

displayName 未填充到 Cloud Functions onCreate 电子邮件+密码触发器中的事实是预期的.该函数由第一个 API 调用 (createUserWithEmailAndPassword()) 触发,而显示名称由第二个 API 调用 (updateProfile) 设置.

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

通常的解决方法是创建一个云函数来更新用户配置文件,如下所示:Firebase Auth+Functions |使用 displayName 创建用户

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.

这篇关于firebase auth onCreate 触发器应该有更多数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆