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?
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"
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With