I want to create a cloud function it will trigger when a user is create image then add a additional field named wallet but from cloud functions and it's value become 0 like this wallet image at the same place but I can't understand how can node.js can get the user mobile number to add this field because it will run once per user because when user will recharge it will not execute.
How can I achieve that? here's my code:
My Code was not worked
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions
// firebaseUser.initializeApp(functions.config().firebase);
exports.onUserCreate = functions.firestore
.document("Users/{mobile}")
.onCreate(async (snap, context) => {
const values = snap.data();
// send wallet value to the fields
await db.collection("Users").document(values.Mobile).add({
Wallet: `0`,
});
});