@firebase/app-check:FirebaseError:AppCheck:ReCAPTCHA 错误

问题描述 投票:0回答:1

我在我的 JavaScript Web 应用程序中实现了 App Check reCAPTCHA Enterprise 流程。我遵循了文件中提到的所有内容。在 Firebase 控制台中启用 AppCheck,注册 Web 应用,并在 GCP 控制台中启用 reCAPTCHA Enterprise API。创建站点密钥并将该密钥添加到 Firebase 应用检查控制台中。在我的项目中添加了依赖项并为AppCheck编写了代码。

问题是在本地主机中运行代码时,我添加了以下行以在本地主机中运行,如文档所述。运作良好

self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;

当我部署代码时,我删除了该行并部署了它。删除该行后出现以下错误。我错过了什么?

    @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.

我在下面添加 js 文件的代码,并使用模块类型将此文件称为我的 HTML 文件。

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 };

特定文档的安全规则

enter image description here

我的 HTML 代码

    const q = query(collection(db, "PhoneAuthdeyaPayUsers"), where("PhoneNumber", "==", userphonum));
    
    const querySnapshot = await getDocs(q);
    querySnapshot.forEach((doc) => {
        // doc.data() is never undefined for query doc snapshots
        console.log(doc.id, " => ", doc.data());
    
        if (doc.exists) {
           console.log("Document data:", doc.data());
           var FailedACHTransactionsCount = doc.data().FailedACHTransactionsCount;
           var AccountStatus = doc.data().AccountStatus || "Active";                           
        }
  });
firebase firebase-authentication firebase-app-check recaptcha-enterprise
1个回答
0
投票

我在

Firestore rules playground
上复制了你的问题,我注意到你错放了牙套。这是更新后的规则

//move the curly brace from line1 to line2

service cloud.firestore {
match /databases/{database}/documents {
  match /PhoneAuthdeyaPayUsers/{document} {

  allow read: if true;
  allow create: if true;
  allow update: if true;
//line1
    match /PhoneAuthdeyaPayUsers/{document}/PersonalAccount/{document1} {

    allow read: if true;
    allow write : if resource.data.PhoneNumber == document;
    allow update: if resource.data.PhoneNumber == document;
}
} //line2
}
}

image

当您使用子集合时,您可以参阅本文档构建 Cloud Firestore 安全规则

© www.soinside.com 2019 - 2024. All rights reserved.