问题
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