forked from firebase/snippets-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callable.js
51 lines (45 loc) · 1.38 KB
/
callable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// [START fb_functions_imports]
import firebase from "firebase/app";
import "firebase/functions";
// [END fb_functions_imports]
function initialize() {
// [START fb_functions_initialize]
firebase.initializeApp({
// Your Firebase Web SDK configuration
// [START_EXCLUDE]
projectId: "<PROJECT_ID>",
apiKey: "<API_KEY>",
// [END_EXCLUDE]
});
const functions = firebase.functions();
// [END fb_functions_initialize]
}
function callAddMessage() {
const messageText = "Hello, World!";
// [START fb_functions_call_add_message]
var addMessage = firebase.functions().httpsCallable('addMessage');
addMessage({ text: messageText })
.then((result) => {
// Read result of the Cloud Function.
var sanitizedMessage = result.data.text;
});
// [END fb_functions_call_add_message]
}
function callAddMessageError() {
const messageText = "Hello, World!";
// [START fb_functions_call_add_message_error]
var addMessage = firebase.functions().httpsCallable('addMessage');
addMessage({ text: messageText })
.then((result) => {
// Read result of the Cloud Function.
var sanitizedMessage = result.data.text;
})
.catch((error) => {
// Getting the Error details.
var code = error.code;
var message = error.message;
var details = error.details;
// ...
});
// [END fb_functions_call_add_message_error]
}