我正在使用这个firebase与next.js。
我尝试将AppCheck reCaptcha添加到config中,我遵循了文档和一些建议,但当我运行yarn build
时
生成失败,出现下一个错误:
ReferenceError: document is not defined
at makeDiv (file:///home/runner/work/physician_me_client/physician_me_client/node_modules/firebase/node_modules/@firebase/app-check/dist/esm/index.esm2017.js:1093:26)
at initializeV3 (file:///home/runner/work/physician_me_client/physician_me_client/node_modules/firebase/node_modules/@firebase/app-check/dist/esm/index.esm2017.js:1038:19)
at ReCaptchaV3Provider.initialize
这是我的firebase配置文件:
/* eslint no-undef: 0 */
import {
initializeAppCheck,
ReCaptchaV3Provider,
getToken,
} from 'firebase/app-check';
if (firebaseConfig?.projectId) {
const app = initializeApp(firebaseConfig);
auth = getAuth(app);
firestore = getFirestore(app);
firebase = app;
storage = getStorage();
googleProvider = new GoogleAuthProvider();
if (app.name && typeof window !== 'undefined') {
analytics = getAnalytics(app);
}
// Pass your reCAPTCHA v3 site key (public key) to activate(). Make sure this
// key is the counterpart to the secret key you set in the Firebase console.
if (IS_PRODUCTION && RECAPTCHA_SITE_KEY) {
const appCheck = initializeAppCheck(app, {
provider: new ReCaptchaV3Provider(RECAPTCHA_SITE_KEY as string),
isTokenAutoRefreshEnabled: true,
});
getToken(appCheck)
.then(() => {
console.log('success');
})
.catch(error => {
console.log(error.message);
});
}
}
1条答案
按热度按时间kzipqqlq1#
我得到了同样的错误。这个检查帮助我: