Firebase + Flutter - Cloud functions onCall result in “unauthenticated” error from Android app

耗尽温柔 提交于 2020-04-13 06:46:42

问题


I have deployed the following test https.onCall function to Cloud Functions on firebase - deployed using node 10:

export const helloWorld = functions.https.onCall((data, context) => {

    return {
        "message": "Hello, world",
    }

}); 

This function returns as expected when tested from a node environment.

However, within my flutter (android) app - using the Cloud functions plugin for Flutter, I'm getting the following authentication error, despite being logged in (via phone number auth):

Flutter code:

void _checkAuth() async { 

    print("Check auth");
    final FirebaseAuth _auth = FirebaseAuth.instance;
    var user = await _auth.currentUser();

    print(user.toString());

    _testFunCall();
}

void _testFunCall() async {
    HttpsCallable callable = CloudFunctions.instance
        .getHttpsCallable(functionName: 'helloWorld');

    try {
        final HttpsCallableResult result = await callable.call();
        print(result.data);

    } on CloudFunctionsException catch (e) {
        print('caught firebase functions exception');
        print(e.code);
        print(e.message);
        print(e.details);
    } catch (e) {
        print('caught generic exception');
        print(e);
    }
}

Error:

I/flutter ( 4662): caught firebase functions exception
I/flutter ( 4662): UNAUTHENTICATED
I/flutter ( 4662): Unauthenticated
I/flutter ( 4662): null

Any ideas?


回答1:


The problem was using Node 10 when deploying to cloud functions.

Node 10 is currently in beta. Switched down to node 8 and it works fine:

In package.json in your cloud functions dir, switch:

  "engines": {
    "node": "10"
  },

to:

  "engines": {
    "node": "8"
  },


来源:https://stackoverflow.com/questions/56120115/firebase-flutter-cloud-functions-oncall-result-in-unauthenticated-error-fr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!