Skip to content

Latest commit

 

History

History
55 lines (37 loc) · 2.38 KB

FUNCTIONS.md

File metadata and controls

55 lines (37 loc) · 2.38 KB

Cloud Functions

Added in plugin version 7.1.0, by breningham

Cloud Functions?

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.

Learn more here..

Note that you don't need to enable this feature in the plugin unless you want to call those Cloud Functions from your app.

Enabling Cloud Functions

To add this feature to your project, either:

  • Remove firebase.nativescript.json from the root of the project and run npm 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.

API

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.

httpsCallable

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));