Added in plugin version 7.1.0, by breningham
Cloud Functions for Firebase lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment. There's no need to manage and scale your own servers.
Note that you don't need to enable this feature in the plugin unless you want to call those Cloud Functions from your app.
To add this feature to your project, either:
- Remove
firebase.nativescript.json
from the root of the project and runnpm i
, or - Edit that file and add
"functions": true
.
In both cases, remove the /platforms
folder afterwards so the required native library will be added upon the next build.
You can use either the Web API syntax (easy for interoperability with a web version of your app), or our custom native syntax. Use whichever syntax you like most - the underlying implementation is the same.
This example uses the Cloud Function as implemented here.
Native API
import * as firebase from "nativescript-plugin-firebase";
const fn = firebase.functions.httpsCallable("helloName");
fn("Nativescript-Plugin-Firebase!")
.then((dataCue: any) => console.log("Callable Function Result: " + dataCue.message))
.catch((errorMessage: string) => console.log("Callable Function Error: " + errorMessage));
Web API
const firebaseWebApi = require("nativescript-plugin-firebase/app"); // mind the /app!
const fn = firebaseWebApi.functions().httpsCallable("helloName");
fn("Nativescript-Plugin-Firebase!")
.then((dataCue: any) => console.log("Callable Function Result: " + dataCue.message))
.catch((errorMessage: string) => console.log("Callable Function Error: " + errorMessage));