I want to use Firebase App Check in Gatsby Project.I have completed the App registration in the Firebase console.
In my project:
import { initializeApp } from "firebase/app";
import { initializeAppCheck, ReCaptchaV3Provider, getToken } from "firebase/app-check";
const app = initializeApp({
// My firebase configuration object
});
const appCheck = initializeAppCheck(app, {
provider: new ReCaptchaV3Provider('MY_RECAPTCHA_PUBLIC_KEY'),
isTokenAutoRefreshEnabled: true
});
getToken(appCheck)
.then(() => {
console.log('success')
})
.catch((error) => {
console.log(error.message)
})
But, it not working and got the error:
@firebase/app-check: FirebaseError: AppCheck: Fetch server returned an HTTP error status. HTTP status: 403. (appCheck/fetch-status-error).
So, can anyone help me check where the problem is? How to solve?
Thanks!
Go to your Firebase Project in Google Cloud Console: https://console.cloud.google.com/apis/credentials
Click on the name of your Firebase API Key under "API Keys".
"API restrictions"
If you are restricting use of your API key, make sure you include:
Selected APIs: Firebase App Check API
Do NOT add localhost to ReCaptcha's accepted domains. The Google Firebase docs are clear you SHOULD NOT add localhost to the allowed domains like @uponly suggested ref: https://firebase.google.com/docs/app-check/web/debug-provider?authuser=0&hl=en#web-version-9
Use the steps more clearly outlined in the "Use the debug provider on localhost" section here
TLDR;
window.FIREBASE_APPCHECK_DEBUG_TOKEN=true right before you call initializeAppCheck to tell your code to request a debug tokenAppCheck debug token:Adding onto @jprio's answer:
If you are using an unrestricted API key and using ReCaptchaEnterprise, you must make sure that you correctly have the appropriate domains set for your Recaptcha Enterprise Site Key.

