在Firebase功能CLI中模拟用户创建 [英] Simulate user-creation in Firebase functions CLI
问题描述
我正在编写一个在Firebase中创建新用户时将触发的函数.调试此功能需要花费很多时间,因为我为每个更改都部署了云功能.我使用Firebase CLI来模拟数据库中的其他事件,但无法弄清楚如何正确地模拟用户创建(使用所有参数).
要启动CLI,请运行:
firebase实验性:功能:壳
我的功能是:
exports.createTreeForNewUser = functions.auth.user().onCreate(event => {const user = event.data;console.log(user.uid);console.log(user.displayName);console.log(user.email);console.log(user.photoURL);console.log(user.metadata.creationTime);返回null;});
当我在Firebase CLI中运行以下命令时:
createTreeForNewUser()
它会打印 undefined
4次,然后出现一个异常,因为它无法从 undefined
中提取 creationTime
.这种行为是有道理的,但是无论我尝试了什么,我都无法弄清楚如何正确传递 event
(以便该函数能够提取我需要的所有参数).>
问题是:如何正确设置 event
参数的情况下运行 createTreeForNewUser
?
谢谢!斯拉维克
将用户对象传递给函数:
createTreeForNewUser({uid:"xxx",displayName:'约翰',电子邮件:"foo@bar.com",photoURL:'https://...',元数据:{creationTime:123}})
I'm writing a function that is triggered whenever a new user is created in Firebase. Debugging this function takes me ages because I deploy the cloud function for every single change. I use Firebase CLI to simulate other events in the database, but I can't figure out how to simulate a user creation correctly (with all the params).
To start the CLI I run:
firebase experimental:functions:shell
My function is:
exports.createTreeForNewUser = functions.auth.user().onCreate(event => {
const user = event.data;
console.log(user.uid);
console.log(user.displayName);
console.log(user.email);
console.log(user.photoURL);
console.log(user.metadata.creationTime);
return null;
});
When I run the following command in the Firebase CLI:
createTreeForNewUser()
it prints undefined
4 times, followed by an exception because it can't extract creationTime
from undefined
.
This behavior makes sense, but no matter what I tried, I couldn't figure out how to pass the event
correctly (so that the function will be able to extract all the params I need).
The question is:
How do I run the createTreeForNewUser
with the event
param set correctly?
Thanks! Slavik
Pass the user object to the function:
createTreeForNewUser({
uid: 'xxx',
displayName: 'John',
email: 'foo@bar.com',
photoURL: 'https://...',
metadata: {creationTime: 123}
})
这篇关于在Firebase功能CLI中模拟用户创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!