Flutter - Firebase callable functions with region not working

153

After some testing and the comment from Peter Koltai, the solution is defining the region in both, flutter and cloud functions:

flutter:

final result = await FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('myCallableFunction').call();

cloud functions:

exports.myCallableFunction = functions.region("europe-west1").https.onCall((data, context) => {
   // ... return result
});

Of course, this makes sense, because as the caller, I want to call the callable functions out of the "europe-west1" region. This gives, if required, the flexibility to call different functions for different regions.

Share:
153
Yetispapa
Author by

Yetispapa

Updated on January 03, 2023

Comments

  • Yetispapa
    Yetispapa over 1 year

    we currently facing the problem in our flutter app, that httpsCallable functions which are defined with a region, in our case "europe-west1", is throwing an exception:

    [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: [firebase_functions/internal] Response is not valid JSON object.
    
    #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
    #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
    <asynchronous suspension>
    #2      MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:23:24)
    <asynchronous suspension>
    #3      HttpsCallable.call (package:cloud_functions/src/https_callable.dart:35:37)
    <asynchronous suspension>
    
    #0      MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:39:7)
    <asynchronous suspension>
    #1      HttpsCallable.call (package:cloud_functions/src/https_callable.dart:35:37)
    <asynchronous suspension>
    

    As far, as we tested, it makes no difference, if we define the region in flutter accordingly to docs:

    final result = await FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('myCallableFunction').call();
    

    Or directly in the cloud function:

    exports.myCallableFunction = functions.region("europe-west1").https.onCall((data, context) => {
       // ... return result
    });
    

    If we remove the region on both lines above, the callable function is working and returning the expected result.

    Is there something, what I miss or is there currently an issue in flutter itself?

    • Peter Koltai
      Peter Koltai about 2 years
      You need both, in Cloud Functions and in Flutter. Have you re-deployed your functions after this change?
    • Peter Koltai
      Peter Koltai about 2 years
      This works for me for the Node.js part: const functions = require("firebase-functions").region('europe-west3'); and then: exports.something = functions.https.onCall.... Dart side I have the same as yours.
    • xbalaj
      xbalaj about 2 years
      Go and check what is the response of the endpoint result, print it. Then you will probably know.