【问题标题】:Firebase AppCheck gives 'appCheck is not a function' when using the client SDKFirebase AppCheck 在使用客户端 SDK 时给出“appCheck 不是函数”
【发布时间】:2021-07-31 15:59:30
【问题描述】:

我在项目中初始化 AppCheck 时遇到错误。

Firebase 版本:“^8.8.1”。

这是我的配置文件:

import firebase from "firebase/app";
import "firebase/functions";

const firebaseConfig = {
    apiKey: "--",
    authDomain: "--",
    projectId: "--",
    storageBucket: "--",
    messagingSenderId: "--",
    appId: "--"
};

const check = firebase.appCheck() // here is the error
check.activate('appCheckKey', true)

const app = firebase.initializeApp(firebaseConfig)
const functions = firebase.functions()

export {
    app,
    functions
}

请注意,我在这里使用的是虚拟数据,因为密钥是敏感信息。

这是我从 Webpack 得到的错误:

firebase.js?dc59:13 Uncaught TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_0__.default.appCheck is not a function
    at eval (firebase.js?dc59:13)
    at Module../src/firebase.js (app.js:1173)
    at __webpack_require__ (app.js:849)
    at fn (app.js:151)
    at eval (SorteoForm.vue?0e40:55)
    at Module../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader-v16/dist/index.js?!./src/components/SorteoForm.vue?vue&type=script&lang=js (app.js:938)
    at __webpack_require__ (app.js:849)
    at fn (app.js:151)
    at eval (SorteoForm.vue?a886:1)
    at Module../src/components/SorteoForm.vue?vue&type=script&lang=js (app.js:1149)

知道可能是什么吗? 谢谢!

【问题讨论】:

    标签: firebase webpack firebase-app-check


    【解决方案1】:

    您需要导入类似于 Firestore 的应用检查和功能。

    import firebase from "firebase/app";
    import "firebase/functions";
    import 'firebase/app-check';
    // Import app-check ^
    
    
    const check = firebase.appCheck();
    check.activate('appCheckKey', true);
    

    【讨论】:

    • 谢谢它有效。另外,我必须在使用 AppCheck 之前初始化应用程序。
    【解决方案2】:

    当您使用版本 8(命名空间)时 - 将其作为脚本标记添加到您的头部:

    https://www.gstatic.com/firebasejs/8.10.0/firebase-app-check.js

    【讨论】:

      猜你喜欢
      • 2022-01-03
      • 1970-01-01
      • 2021-12-13
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-05
      • 2021-09-26
      相关资源
      最近更新 更多