skip to Main Content

I can successfully enable App Check for my Firebase Functions and they are working as expected when I deploy them to the Firebase server. However, when I try to test with Firebase emulator, the functions with App Check will return unauthenticated error.

How can I make the emulator return a valid response? Is there any way like adding the debug token in the emulator, like the Firebase console?

2

Answers


  1. Chosen as BEST ANSWER

    The trick here is to turn off App Check when the functions is running on emulator. This can be achieve by checking the environment variable FUNCTIONS_EMULATOR.

    exports.hello = functions
      .runWith({
        enforceAppCheck: process.env.FUNCTIONS_EMULATOR !== "true", 
      })
      .https.onCall((data, context) => {
        return "Hello";
      });
    

  2. As per my undestanding base on this post. The use of the app check using local emulators is not possible. This is presumably because localhost is not listed as an allowed domain, resulting in unathenticated error.

    A workaround was recommended on the same post. Another user successfully set up app check by adding this snippet right above the call to activate appCheck.

    if (process.env.NODE_ENV !== 'production') {
      self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;
    }
    
    const appCheck = firebase.appCheck();
    appCheck.activate(
      process.env.REACT_APP_FIREBASE_APP_CHECK_SITE_KEY,
      true,
    );
    

    Hope this will help you on your use case. for more information you can check the orginal post.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search