Open davwheat opened 4 years ago
@davwheat try this:
import firebase from 'gatsby-plugin-firebase'
firebase.functions = firebase.app().functions('europe-west1') // Your region here.
const myFunction = firebase.functions.httpsCallable(
'myFunction' // Your function name here.
)
// Then use your cloud function as usually.
Ooh I didn't think about the fact that app was exported too! I'll try that.
One more thing is needed to have gatsby build
successful. You'd have to use typeof window !== 'undefined'
check as Gatsbyjs docs suggest at How to check if window is defined. So the code above would become:
import firebase from 'gatsby-plugin-firebase'
firebase.functions = typeof window !== 'undefined' && firebase.app().functions('europe-west1') // Your region here.
const myFunction = firebase.functions
? firebase.functions.httpsCallable('myFunction') // Your function name here.
: () => Promise.resolve(null)
// Then use your cloud function as usually.
Hmm I'll take a look into this issue once I have the time. That seems a little annoying.
If that's the only way to go about this, would yall want me to do all these aliases and export them from gatsby-plugin-firebase
so you won't have to do it?
@yzalvov You can always just stick it in a useEffect
, which looks much cleaner in my opinion.
The region for firebase functions must be declared at initialisation, but this package doesn't provide any way to give a region.
This is really important to reduce latency as much as possible.
https://firebase.google.com/docs/functions/locations#client-side_location_selection_for_callable_functions