这个
.onCreate()
将为在Firebase Auth中创建的每个用户触发函数,但无法有条件地触发它。如果您不想每次都触发该函数,那么可以使用
callable function
相反
const createUser = async () => {
const { user } = await createUserWithEmailAndPassword(auth, email, password);
if (userShouldBeAdmin()) {
// call the cloud function to update document/custom claims
const updateUserType = httpsCallable(functions, 'updateUserType');
const res = await updateUserType({ ...data })
}
}
export const updateUserType = functions.https.onCall((data, context) => {
const { uid } = context.auth;
// When using onRequest() functions, you must manually verify user's ID Token
// TODO: Check if user is meant to be public as per your logic
// if yes, update relevant documents and claims
// else return an error.
return;
});
此外,不能将任何自定义参数传递给
onCreate()
但如果需要,可以使用可调用函数来实现。