Firebase cloud functions
Put very simply, Firebase cloud functions are pieces of javascript code that reside on the server and run each time a request from the client is made.
Each such request has meta information - context - from which we can extract authentication information, such as the user id. Each request also has a data object, to which we can pass information from the client.
Here is how one can call a cloud function from the client:
firebase.app().functions().httpsCallable('inviteUser')
.inviteUser(
{ email: email, fullname: 'John Doe', userId: generateUUID() }
);
And here is how the function responding to this user call looks like:
exports.inviteUser = functions
.https.onCall(async (data, context) => {
let company = await getCompanyNameFromUserId( context.auth.uid )
const { fullname, email, userId } = data;
// do the wiring with the vars extracted from data
// create user account, add user to company, send verification email
...
return ...
);
});
Last updated
Was this helpful?