1

I am trying to execute my callable function in my cloud_functions but on the front-end flutter side, I am getting the error [firebase_functions/unauthenticated] UNAUTHENTICATED.

I was using callable functions earlier in my cloud functions and it was working fine but now I created a new cloud function that does not work like the others.

To ensure the function was authenticated, I went the GCP and enabled allUsers as referenced here to use this function and I ensured that I was authenticated in the app front-end flutter as well.

cloud functions

const functions = require("firebase-functions");
const admin = require('firebase-admin')
// const { CloudTasksClient } = require('@google-cloud/tasks');
admin.initializeApp()
const log = functions.logger.log
function join(t, a, s) {
    function format(m) {
        let f = new Intl.DateTimeFormat('en', m);
        return f.format(t);
    }
    return a.map(format).join(s);
}

exports.updateTime = functions.https.onCall((data, context) => {
    log("Update Time")
    let { dateString, uid, id } = data
    log(dateString)
    log(uid)
    log(id)
    // Get Date from time in format mm-dd-yyyy

    let entryDate = new Date(dateString);
    let a = [{ month: 'numeric' }, { day: 'numeric' }, { year: 'numeric' }];
    let date = join(entryDate, a, '-');
    log(date)

    return ['Hello']
})

flutter

  Future<void> createNotification(Map data) async {
    print("Creating Notification");
    assert(FirebaseAuth.instance.currentUser != null);
    try {
      HttpsCallable callable =
          FirebaseFunctions.instance.httpsCallable('updateTime');
      HttpsCallableResult result = await callable.call(data);
      print(result.data);
    } on FirebaseFunctionsException catch (e) {
      print('An error occurred while calling createNotification');
      print(e);
    } catch (e) {
      print("Uncaught error");
      print(e);
    }
  }
pythonNovice
  • 1,130
  • 1
  • 14
  • 36
  • "I ensured that I was authenticated in the app front-end flutter as well." Can you show how you ensure that, as the code you shared is not doing anything to check that? I recommend doing `assert(FirebaseAuth.instance. currentUser != null)` as the first line in your `createNotification` function. – Frank van Puffelen Aug 11 '21 at 18:54
  • Hey Frank! Yes, I have updated the function for this and I am still getting an Unauthenticated error. Right before I call this function, I also do get an additional couple of lines `W/DynamiteModule(14853): Local module descriptor class for providerinstaller not found. I/DynamiteModule(14853): Considering local module providerinstaller:0 and remote module providerinstaller:0 W/ProviderInstaller(14853): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0`. Not sure if that's the reason, but I've had them before and it worked – pythonNovice Aug 11 '21 at 20:45
  • Actually now for whatever reason, it is letting me make the calls now. Thanks for your help! – pythonNovice Aug 11 '21 at 20:56

0 Answers0