My issue is the current firebase AUTH is kind of blind to what kind of user is getting created, I want to create a cloud function that can handle 2 different types of user or at least disable the creation of the other type of user (meaning if the user is not an admin then it will be created only from the front-end and and the cloud function wont be ran only if the user is admin ) any idea how to achieve this kind of behavior and make the .onCreate() method distinguish between the 2 different types of users getting created ?
export const accountCreate = functions.auth.user().onCreate((user) => {
const expiresIn = 60; // test 1h //172800 === 48h
const createdAt = admin.firestore.Timestamp.now().toDate();
createdAt.setSeconds(createdAt.getSeconds() + expiresIn);
const payload = {
user: 'Admin', // later dynamic
verifiedEmail: false,
sharedId: user.uid,
createdAt: admin.firestore.Timestamp.now(), //admin.firestore.FieldValue.serverTimestamp(),
premiumUntill: admin.firestore.Timestamp.fromDate(createdAt), //.toMillis() + 86400000, // +24h days //
clients: [],
unit: '',
};
return db
.collection('Data')
.doc(user.uid)
.set(payload)
.catch((err: any) => {
console.log(err);
});
});