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);
}
}