[英]How to use Firebase App Check in React. 403 error
I want to use Firebase App Check in Gatsby Project.I have completed the App registration in the Firebase console.我想在 Gatsby 项目中使用 Firebase App Check。我已经在 Firebase 控制台中完成了 App 注册。
In my project:在我的项目中:
import { initializeApp } from "firebase/app";
import { initializeAppCheck, ReCaptchaV3Provider, getToken } from "firebase/app-check";
const app = initializeApp({
// My firebase configuration object
});
const appCheck = initializeAppCheck(app, {
provider: new ReCaptchaV3Provider('MY_RECAPTCHA_PUBLIC_KEY'),
isTokenAutoRefreshEnabled: true
});
getToken(appCheck)
.then(() => {
console.log('success')
})
.catch((error) => {
console.log(error.message)
})
But, it not working and got the error:但是,它不起作用并出现错误:
@firebase/app-check: FirebaseError: AppCheck: Fetch server returned an HTTP error status.
@firebase/app-check: FirebaseError: AppCheck: Fetch 服务器返回 HTTP 错误状态。 HTTP status: 403. (appCheck/fetch-status-error).
HTTP 状态:403。(appCheck/fetch-status-error)。
So, can anyone help me check where the problem is?那么,谁能帮我检查一下问题出在哪里? How to solve?
怎么解决?
Thanks!谢谢!
Go to your Firebase Project in Google Cloud Console: https://console.cloud.google.com/apis/credentials在 Google Cloud Console 中转到您的 Firebase 项目: https : //console.cloud.google.com/apis/credentials
Click on the name of your Firebase API Key under "API Keys".在“API Keys”下点击您的 Firebase API Key 的名称。
"API restrictions" “API 限制”
If you are restricting use of your API key, make sure you include:如果您限制使用 API 密钥,请确保您包括:
Selected APIs : Firebase App Check API选定的 API :Firebase 应用检查 API
Adding onto @jprio's answer:添加到@jprio 的答案中:
If you are using an unrestricted API key and using ReCaptchaEnterprise, you must make sure that you correctly have the appropriate domains set for your Recaptcha Enterprise Site Key.如果您使用不受限制的API 密钥并使用 ReCaptchaEnterprise,则必须确保为您的 Recaptcha Enterprise 站点密钥正确设置了适当的域。
I had a similar issue.我有一个类似的问题。 For me, the error got resolved when I used the correct appId in the firebase config.
对我来说,当我在 firebase 配置中使用正确的 appId 时,错误得到了解决。 It turns out that I had set up two apps on firebase and I downloaded the wrong json file which had a different appId.
事实证明,我在 firebase 上设置了两个应用程序,并且下载了具有不同 appId 的错误 json 文件。
According to firebase support, appIds are unique per app.根据 firebase 支持,每个应用的 appId 都是唯一的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.