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

1,722

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"
  },
Share:
1,722
dsg38
Author by

dsg38

Updated on December 11, 2022

Comments

  • dsg38
    dsg38 over 1 year

    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?

  • dsg38
    dsg38 about 5 years
    Presumably they will update the status of the beta here - node 8 is currently the only recommended engine: firebase.google.com/docs/functions/…
  • Andrey Gordeev
    Andrey Gordeev about 4 years
    Unfortunately, this issue happens even with node 8
  • Yakub Pasha
    Yakub Pasha almost 4 years
    hey @AndreyGordeev, were you able to find the solution for tis issue