Search code examples
firebasegoogle-cloud-functionsfirebase-tools

Cannot execute cloud functions in firebase emulator


I am trying to use the Firebase emulator to deploy my firebase flutter app, and everything works fine except when I call a method that calls a cloud function. I get an error [firebase_functions/unauthenticated] Unauthenticated and my cloud function doesn't execute(the rest of the method executes fine). I don't have this problem if I do it in production mode. At first I thought it was a security rules problem so I did:

rules_version = '2';
service cloud.firestore {
 match /databases/{database}/documents {
  match /{document=**} {

  allow read, write: if true;
}

}
}

but still didn't work. I also tried this thread Newly Created Firebase Functions Throwing UNAUTHENTICATED Error and allowed all users to access the cloud functions but still didn't work. I don't know why is this happening in the emulator and not in production mode, and how to solve it. Help please.


Solution

  • The error was that I was not accesing the cloud functions from the emulator. I was accesing the real cloud functions from my production enviroment. I am working in flutter so I solved it by adding

    FirebaseFunctions functions = FirebaseFunctions.instanceFor( region :  "europe-west1");
    functions.useFunctionsEmulator('localhost', 5001);
    var delete = functions.httpsCallable(deleteShoppingListsCollectionsFunction).call(data);
    

    Before that what I was doing was:

    var delete = FirebaseFunctions
             .instanceFor( region :  "europe-west1")
             .httpsCallable(deleteShoppingListsCollectionsFunction).call(data);