Invoke Callable functions
We get a reference to the callable function, and call it like a regular function.
get a functions helper: set the firebase project and the region
Since a client can interact with Cloud Functions from separate Firebase projects, we specify the project we target. We do so indirectly, by providing the app helper, which already identifies the project.
Since a cloud function can live across regions as separate regional instances, we specify the region we target. We use one of the regional identifiers that we set in the Callable options. If omitted, the client SDK targets us-central1, which errors if no instance runs there.
const functions = getFunctions(app, "europe-west1")
get a handle over the Callable function
We also provide the type arguments:
const requestPokemonCF = httpsCallable<ReqData, ResData>(functions, "requestPokemon")
invoke and handle the result
The payload, if any, is of type ReqData. The returned value is of type HttpsCallableResult<ResData>. We read the data property:
const result = await requestPokemonCF({ number: 151 })
result.data // ResData