Firebase functions user().onCreate: Pass parameters [duplicate]

≯℡__Kan透↙ 提交于 2021-02-11 14:27:44

问题


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;
});

回答1:


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.



来源:https://stackoverflow.com/questions/62554225/firebase-functions-user-oncreate-pass-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!