I'm using a onCreate function for Firestore to detect user signup and create a document using his user id. The problem is the function works sometimes and doesn't work other times. Also, I'm getting a "Function returned undefined, expected Promise or value" error all the time whenever the function run. I have tried many solutions which were given on similar questions but still no luck.
export const createNewUser = functions.auth.user().onCreate(user => {
const userId = user.uid;
const updateData = {
ads_watched: 0,
coins: 20000,
gems: 0
};
admin.firestore().doc("cashon/" + userId)
.set(updateData)
.then(writeResult => {
console.log("User Created result:", writeResult);
return null;
})
.catch(err => {
console.log(err);
return null;
});
});