I'm using firebase admin SDK to create new User to my web app.
// function to create user and store additional info in firestore
exports.createUser = functions
.https.onCall((data, context) => {
admin.auth().createUser({
phoneNumber: data.phoneNumber,
displayName: data.displayName,
}).then((user) => {
// store data in firestore
admin.firestore().collection("user").doc(user.uid).set({...data});
}).catch((err) => {
// handle error
});
});
When I call the function from the client (attach it to onClick event) I want to wait till user is successfully added in firestore and invoke the fetchUser function so I can see the new list of data with the newly added user. Currently fetchUser gets called and page refreshes but I cannot see the newly added user before refreshing it.
const createUser = functions.httpsCallable('createUser');
const createNewUser = () => {
createUser({
phoneNumber: "+1111111111111",
displayName: "test",
introduction: "testcreate",
})
.then((res) => {
fetchUser(); // fetchUser just fetches user data from firestore and rerenders page
})
.catch((err) => {
console.log(err);
});
};
To summarize, can I know when cloud function will complete its job and run a particular function or task ?