【发布时间】:2020-06-12 06:12:28
【问题描述】:
我正在尝试编写一个在创建用户时发送欢迎电子邮件的函数。我跟着this 教程,它说可以使用user.displayName 访问新创建的用户的displayName,尽管它一直为我返回null。我意识到发生这种情况的可能原因(如果我错了,请纠正我)是注册和设置用户的 displayName 发生在客户端的两个单独步骤中,因此当onCreate 被触发时,user.displayName 自然会是空值。这是我的客户端代码,供参考:
fb.auth().createUserWithEmailAndPassword(payload.email, payload.password).then(user => {
return user.user.updateProfile({ displayName: payload.name, });
}).catch(/* ... */);
我正在寻找的是在user.updateProfile 上触发的云功能。我查看了auth.user().onOperation 函数(找到here),但是当我尝试将此函数部署到firebase 时,我收到错误Error: Functions did not deploy properly.(有帮助,ikr),我猜这与onOperation 函数是 private(如果我错了,请纠正我)。
有什么办法可以做我想做的事吗?如果是这样,怎么做?或者,有没有办法在createUserWithEmailAndPassword 上设置displayName,以便我可以继续使用onCreate 功能?
这是我当前的onCreate 代码:
exports.sendWelcomeEmail = functions.auth.user().onCreate(user => {
console.log('name:', user.displayName);
});
这是我对onOperation 函数的尝试:
exports.sendWelcomeEmail = functions.auth.user().onOperation(user => {
console.log('user:', user);
}, 'updateProfile');
【问题讨论】:
标签: javascript firebase firebase-authentication google-cloud-functions