firebasegoogle-cloud-firestorevuejs2progressive-web-appsrecaptcha-v3

How to get firebase App Check working with cloud firestore in a web app


I try to get App Check working in my vue.js pwa. Using the latest firebase sdk and by following steps here https://firebase.google.com/docs/app-check/web/recaptcha-provider

My api key (https://console.cloud.google.com/apis/credentials/key..) is not limited to any API restrictions. I did add some Application Restrictions on https tho including my project domains.

Everything works fine till i activate appCheck with recaptcha v3 and i get following console errors: enter image description here

FirebaseError: [code=unknown]: Fetching auth token failed: AppCheck: Fetch server returned an HTTP error status. HTTP status: 403. (appCheck/fetch-status-error)

Further more the app can't get any firebase data or auth. I tried in several browsers and without any vpn stuff. In my already installed pwa the App Check error occurs but connection to firebase still works..

Without App Check activated it both works without an issue. Also with an App Check debug token the whole thing just works. I don't understand why it breaks firebase connection even if i haven't enabled enforcement.

I appreciate any tips on how to solve this.


Solution

  • I found the problem i accidently left self.FIREBASE_APPCHECK_DEBUG_TOKEN = true; in my production code.

    Remove this line or only use when in development envirement solved the whole problem

    if (location.hostname === "localhost") {
      self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;
    }
    

    I didn't expect this line to impact browsers where i haven't registered a debug token to fail with the regular appCheck but of course it doesn't make sense to use it in production anyways.