Implement callable cloud functions in Firebase client app

前端 未结 3 1914
不思量自难忘°
不思量自难忘° 2021-01-14 17:13

I have recently discovered the Firebase callable functions which allows me to call HTTPS trigger like function from the client side (and with auth() support).

I stru

相关标签:
3条回答
  • 2021-01-14 17:45

    I just ran into this same problem myself and solved it by installing and importing the @firebase/functions npm package. I found the solution on github here: https://github.com/firebase/firebase-js-sdk/blob/master/packages/functions/README.md

    From the README on github:

    ES Modules

    import firebase from '@firebase/app';
    import '@firebase/functions'
    // Do stuff w/ `firebase` and `firebase.functions`
    

    CommonJS Modules

    const firebase = require('@firebase/app').default;
    require('@firebase/functions');
    
    // Do stuff with `firebase` and `firebase.functions`
    

    Hope that helps! The actual documentation is not very clear about having to do this in order to call the functions.

    0 讨论(0)
  • 2021-01-14 17:48

    About @firebase/functions:

    This package is not intended for direct usage, and should only be used via the officially supported firebase package.

    This worked for me:

    import * as firebase from 'firebase/app'; // Typescript
    // import firebase from 'firebase/app'; // JS
    import 'firebase/functions';
    
    const myCallableFunc = firebase.functions().httpsCallable('myCallableFunc');
    

    I don't know about importing firebase-functions with a CDN but if you're using npm then you don't need the firebase-functions package, just installing firebase will do.

    0 讨论(0)
  • 2021-01-14 18:06

    Follow the steps mentioned here. Firebase cloud functions

    I think there is nothing like firebaseApp.functions.

    0 讨论(0)
提交回复
热议问题