如何在我的Web应用中添加Firebase应用检查SDK?

y1aodyip  于 2022-11-25  发布在  其他
关注(0)|答案(1)|浏览(112)

我已经在我的Firebase console中为我的web应用注册了我的reCAPTCHA v3密钥。现在我想在我的客户端添加应用检查SDK。这些是我在我的index.html中的导入:

<script src="https://www.gstatic.com/firebasejs/9.14.0/firebase-app-compat.js"></script>

<script src="https://www.gstatic.com/firebasejs/9.14.0/firebase-database-compat.js"></script>

<script src="https://www.gstatic.com/firebasejs/9.14.0/firebase-auth-compat.js"></script>`

<script src="https://www.gstatic.com/firebasejs/9.14.0/firebase-app-check-compat.js" async defer></script>

<script src="https://www.google.com/recaptcha/api.js?render=MY_SITE_KEY_HERE" async defer></script>

这是我的javascript

const firebaseConfig = {
  apiKey: "ABCDEF",
  authDomain: "ABCDEFGH.firebaseapp.com",
  projectId: "ABCDEFGHO",
  storageBucket: "project_name.appspot.com",
  messagingSenderId: "123456789",
  databaseURL: "https://project)name.firebaseio.com",
  appId: "1:12345678:web:f4r3rsdf322e112c800"
};

firebase.initializeApp(firebaseConfig);

document.getElementById("submit").addEventListener("click",function(event){

     firebase.initializeAppCheck(firebase.initializeApp(firebaseConfig),{
        provider: new ReCaptchaV3Provider('MY_SITE_KEY_HERE'),
        isTokenAutoRefreshEnabled: true
     });
})

单击submit按钮时,控制台中弹出以下错误:
未捕获(在承诺中)引用错误:未定义ReCaptchaV3提供程序
如何修复此问题?这是安装应用检查SDK的正确方法吗?

tjrkku2a

tjrkku2a1#

您需要添加导入代码

import {ReCaptchaV3Provider} from "firebase/app-check"

相关问题