HTTPS Callable
HTTPS Callable Call functions from your app​
1
exports.addMessage = functions.https.onCall((data, context) => {
2
// ...
3
});
Copied!
to send data back to the client, return data that can be JSON encoded.
To return data after an asynchronous operation, return a promise. The data returned by the promise is sent back to the client.
In client Call the function​
1
var addMessage = firebase.functions().httpsCallable('addMessage');
2
addMessage({text: messageText}).then(function(result) {
3
// Read result of the Cloud Function.
4
var sanitizedMessage = result.data.text;
5
// ...
6
});
Copied!
1
export const getData = functions.https.onCall((data, context) => {
2
// verify Firebase Auth ID token
3
if (!context.auth) {
4
// return { message: 'Authentication Required!', code: 401 };
5
// https://firebase.google.com/docs/functions/callable#handle_errors
6
throw new functions.https.HttpsError(
7
"failed-precondition",
8
"The function must be called " + "while authenticated."
9
);
10
}
11
​
12
// do your things..
13
const uid = context.auth.uid;
14
const query = data.query;
15
​
16
return { message: 'Some Data', code: 400 };
17
});
Copied!
1
exports.helloWorld = functions.https.onCall((data, context) => {
Copied!
1
if (!context.auth) {
2
throw new functions.https.HttpsError(
3
"failed-precondition",
4
"The function must be called " + "while authenticated."
5
);
6
}
7
return { text: "Hello World" };
8
});
Copied!
​
Last modified 2yr ago
Copy link