Firebase函数user().onCreate:传递参数 [英] Firebase functions user().onCreate: Pass parameters

查看:33
本文介绍了Firebase函数user().onCreate:传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2种类型的用户:管理员和普通用户.在我的Firebase数据库中,每个管理员在文本"集合中都有一个文档.因此,当创建一个新用户时,我想检查它是否是管理员.但是,在Flutter客户端上,我无法传递电子邮件和密码以外的任何其他参数,因此,创建帐户的用户是否是管理员,我的功能怎么知道?

I have 2 types of users, admins and normal users. In my firebase database, each admin has a document in a 'texts' collection. So, when a new user is created, I want to check if it is an admin or not. On my Flutter client however, I cant pass any other param than email and password, so how does my function know, if the user that is creating an account is an admin or not?

这是我没有检查的功能:

This is my function without the check:

exports.onAdminCreate = functions.auth.user().onCreate((user) => {
// If user is an admin
try {
    return admin.firestore().collection('texts').doc(user.uid).create({author: user.displayName, text: null});
} catch (e) {
    console.log(e);
    return null;
}
// Else
console.log('No admin');
return null;
});

推荐答案

我认为

I think this other post can be very helpful for you. As you can see there, you can pass parameters to the firebase function using HashMap

Map<String, Object> data = new HashMap<>();
data.put("var1", text);
data.put("var2", text);

您可以在共享链接中看到完整的示例.

You can see the complete example in the shared link.

这篇关于Firebase函数user().onCreate:传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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