4

I tried using firebase cloud functions oncall method directly from my FLUTTER app and it keeps giving me an UNAUTHENTICATED error even when I am logged in Flutter app code

CloudFunctions function = CloudFunctions.instance;
final HttpsCallable createCallable = function.getHttpsCallable(functionName: 'two_create')
  ..timeout = const Duration(seconds: 30);

try {
  final HttpsCallableResult result = await createCallable.call({
    'stay': 'con50',
    'open': false
  });

  print(result.data);
}on CloudFunctionsException catch(e){
  print('-----------------------------------------------');
  print(e.code); print(e.message); print(e.details);
  print('-----------------------------------------------');
}

dynamic user = await FirebaseAuth.instance.currentUser();
print(user.uid);

I got this error

I/flutter (19466): -----------------------------------------------
I/flutter (19466): UNAUTHENTICATED
I/flutter (19466): UNAUTHENTICATED
I/flutter (19466): null
I/flutter (19466): -----------------------------------------------
I/flutter (19466): eMTX6OcYPOSeYdimmCSqjbnnmWM2

I tried printing out the uid to show I am currently signed in and I am currently using an android device for testing.

This is the function I am calling from my app

exports.two_create = functions.https.onCall(async (context,data)=>{
    var oncall = require('./httponcall');

    var text = await oncall.create(admin,allRef.one2,context,data);
    return text;
})

And I didn't get any logs from Firebase console when it was triggered

Mayor
  • 303
  • 2
  • 7
  • Please edit the question to show the function code that you're trying to invoke, and any logs that it might be generating. – Doug Stevenson Apr 05 '20 at 19:58
  • If the function isn't actually being invoked (you find no logs), then contact Firebase support for assistance. https://support.google.com/firebase/contact/support – Doug Stevenson Apr 05 '20 at 19:59
  • This might be a matter of Node version. Please take a look: https://stackoverflow.com/questions/56120115/firebase-flutter-cloud-functions-oncall-result-in-unauthenticated-error-fr – vitooh Apr 06 '20 at 07:01
  • I have the same issue! – Hannah Stark Apr 07 '20 at 22:21
  • 1
    I tried changing the node version I still got the same error – Mayor Apr 09 '20 at 01:16
  • For me the issue was that the invoker was not set on https://console.cloud.google.com/functions/details/ – Hannah Stark Apr 09 '20 at 11:03
  • 1
    I think @HannahStark is referring to this https://cloud.google.com/functions/docs/securing/authenticating#function-to-function, have you checked that? – vitooh Apr 22 '20 at 12:37

1 Answers1

2
  1. first update the firebase tools and dependencies to latest.

https://firebase.google.com/docs/functions/get-started?authuser=0#set-up-node.js-and-the-firebase-cli

npm install firebase-functions@latest firebase-admin@latest --save

npm install -g firebase-tools

  1. after deploy

  2. go to Google cloud console(GCP) not the firebase console GCP sidebar > Cloud functions > select your function go to PERMISSIONS >ADD > "allUsers"> Firebase > Firebase Viewer

do this at your own risk iam not any cloud devloper . i dont know the risk of adding allUsers like this iam new to flutter devlopment

enter image description here

Sumer Singh
  • 468
  • 4
  • 9