Created
May 15, 2020 16:41
-
-
Save katowulf/d50c26dbbb69fbfe3869cf0b4b41fda1 to your computer and use it in GitHub Desktop.
Use Firebase Cloud Functions to call a method from both callable and http requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function callMeAnywhere(uid, foo) { | |
if( !uid ) throw new Error("Must authenticate"); | |
return foo + 'bar'; | |
} | |
functions.https.onCall((data, context) => { | |
const data = callMeAnywhere(context.auth.uid, data.foo); | |
return {data: data}; | |
}) | |
// Use this with https://github.com/firebase/functions-samples/tree/master/authorized-https-endpoint | |
app.get('/foo', (req, res) => { | |
const data = callMeAnywhere(req.user.id, req.params.foo); | |
res.send(data); | |
}); | |
functions.https.onRequest(app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment