I implemented the App Check reCAPTCHA Enterprise process in my javascript web application. I followed everything mentioned in the document. Enabled the AppCheck in the Firebase console, registered the web app, and enabled the reCAPTCHA Enterprise API in the GCP console. Created the site key and added that key in the Firebase app check console. Added the dependencies in my project and wrote code for AppCheck.
The issue is when running the code in localhost, I added the below line to run in localhost as the document says. It’s working fine
self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;
When I deployed the code, I removed that line and deployed it. After removing that line getting the below errors. What am I missing?
@firebase/app-check: FirebaseError: AppCheck: ReCAPTCHA error. (appCheck/recaptcha-error).
at ReCaptchaEnterpriseProvider.getToken (providers.ts:173:22)
at async getToken$2 (internal-api.ts:156:42)
at async Promise.all (index 1)
Error getting documents: FirebaseError: Missing or insufficient permissions.
I am adding the code of my js file below and I am calling this file my HTML file using module type.
var key = "SITE-KEY-HERE"
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js';
import { getAuth, signInWithPhoneNumber, RecaptchaVerifier } from 'https://www.gstatic.com/firebasejs/10.12.2/firebase-auth.js';
import { getFirestore } from 'https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js';
import { collection, getDocs, addDoc, Timestamp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js"
import { query, orderBy, limit, where, onSnapshot } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js"
import { getMessaging } from 'https://www.gstatic.com/firebasejs/10.12.2/firebase-messaging.js';
import { initializeAppCheck, getToken, ReCaptchaEnterpriseProvider } from 'https://www.gstatic.com/firebasejs/10.12.2/firebase-app-check.js';
var firebaseConfig={
apiKey:"API-KEY",
authDomain:"deyapaylive1.firebaseapp.com",
databaseURL:"https://SOME.firebaseio.com",
projectId:"PROJECTID",
storageBucket:"SOME.appspot.com",
messagingSenderId:"ID",
appId:"......"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Initialize other Firebase services
const auth = getAuth(app);
const db = getFirestore(app);
const messaging = getMessaging(app);
// self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;
// Initialize App Check
const appCheck = initializeAppCheck(app, {
provider: new ReCaptchaEnterpriseProvider(key),
isTokenAutoRefreshEnabled: false
});
export { app, db, collection, getDocs, Timestamp, addDoc };
export { query, orderBy, limit, where, onSnapshot };
export { auth, messaging, appCheck, signInWithPhoneNumber, RecaptchaVerifier };