I'm trying to create a cloud function that automatically adds 50 points to the "points" field in the database whenever a new user is created using the "onCreate((user)" function. The goal is to simply detect when a new user is created, retrieve their ID, and update their points to 50 using a cloud function. Here is what the setup looks like:
https://i.sstatic.net/ZqksL.png
Below is the current code I have been working on:
exports.updatepoints = functions.auth.user().onCreate((user) => {
const userID = firebase.auth.currentUser.uid;
return updatepoints(userID)
});
async function updatepoints(userID) {
return firebase.database().ref('mobile_user/' + userID).set(
{
points: 50
});
};
I am new to JavaScript and Firebase, so any advice or guidance would be greatly appreciated.