Angularfire: cloud function with angularfire2

Created on 13 Mar 2017  路  10Comments  路  Source: angular/angularfire

Hi Guys,

I am very excited that the cloud function is working with firebase now !

Just a quick question, does anyone know if angularfire2 support cloud function or we need to use firebase sdk to work with cloud function for now?

Thank you

Most helpful comment

@johanchouquet @yejodido Cloud Functions recently implemented a client SDK for "callable functions" and we have a PR #1532 to support it. So follow that and wait just a little longer.

All 10 comments

You have to use the Firebase CLI to deploy your functions to Firebase. Cloud functions are backend related, not frontend.

As far as I know AngularFire is not related to Cloud Functions

@johnqiuwan Server events are triggered by events. @frankspin89 is right in saying we don't have any direct integrations.

Thank you @davideast and @frankspin89

If I understand correct, we need to use raw firebase sdk to implement cloud functions.

Hi there,

I understand that AngularFire2 is for Frontend purposes, and Cloud Functions are for backend, but it'd be nice to be able to rely on 1 single API (ie AngularFire2) when starting on a new Angular Firebase Project.
It's a bit a pain to have to re-learn every little thing and different detail from one API to another when a dev has to work on Functions, while he knows quite a lot with AngularFire2 API.

I think it'd be great to be able to use AngularFire2 API to fetch data for example, inside a Function, instead of using firebase-admin, by doing admin.firebase().ref(...). The documentation is also different from AngularFire2, with sometimes differences in terms of updates...

As of today, are there any plans to support writing Functions extending AngularFire2 ?

I'd agree with @johanchouquet , especially since much of angularfire is a lightweight wrapper over firebase's rest api, incorporating a simple fetch utility for "cloud function"-specific restful requests might prove useful.

@johanchouquet @yejodido Cloud Functions recently implemented a client SDK for "callable functions" and we have a PR #1532 to support it. So follow that and wait just a little longer.

Any update on when we can expect this PR? I'm hoping with PR #1532 that I will be able to use an angularfire2 wrapper for callable functions and not have to deal with the issue below.

Currently trying to work around it, but I am getting ERROR in <filename hidden>: error TS2339: Property 'functions' does not exist on type 'typeof firebase'.
when trying to import firebase modules directly based on their docs. Strangely enough it will fail to compile the first time, but if I make any changes that causes it to recompile it works fine (meaning I can develop _kindof_ but cannot deploy).

import * as firebase from 'firebase';

// Required for side-effects
import 'firebase/functions';

const createGame = firebase.functions().httpsCallable('myCallableFunction');

UPDATE: For those doing the same thing I am doing, wrapping firebase in an object fixes my problem ... Object(firebase).functions()...for now so I am not depending on this PR anymore. I'm still looking forward to it though!

@Mercieral whenever you get anything like Property 'functions' does not exist on type 'typeof firebase'

you can just cast it as any, so
const createGame = (firebase as any).functions().httpsCallable('myCallableFunction');
would work too.
_I believe it's actually better way to do it anyways_

:)

I see that PR #1532 has been accepted. Are there any examples on how to use this? I tried using like in the firebase docs but I end up with "Object is not a function" error.

@Tristan10 have you found any examples?

Was this page helpful?
0 / 5 - 0 ratings