I have a cloud function that is called by my front-side app in React Native. Here is my cloud function:
exports.listProducts = functions.https.onCall((temp, context) => {
console.log("fired");
return context;
});
And here is how I call the function:
let temp = await functions().httpsCallable("listProducts")(
null,
firebase.auth().currentUser
);
However, I can't acccess the context variable in my cloud function which according to docs should be the Firebase auth. And the console.log in that function does not give me a log.
Any parameters you pass to the callable function are available in the first parameter, which you call temp, but that the Firebase documentation refers to as data.
You don't need to pass the current user to the callable function yourself, as the Firebase SDK already handles that for you, and the server already decoded the current user into context.auth.
For more on both parameters and the auth context, have a look at the Firebase documentation on writing and deploying callable functions, which contains:
Use functions.https.onCall to create an HTTPS callable function. This method takes two parameters: data, and optional context:
// Saves a message to the Firebase Realtime Database but sanitizes the text by removing swearwords. exports.addMessage = functions.https.onCall((data, context) => { // ... });For a callable function that saves a text message to the Realtime Database, for example, data could contain the message text, while context parameters represent user auth information:
// Message text passed from the client. const text = data.text; // Authentication / user information is automatically added to the request. const uid = context.auth.uid; const name = context.auth.token.name || null; const picture = context.auth.token.picture || null; const email = context.auth.token.email || null;