[英]Error in Firebasse"assert.ts:128 Uncaught FirebaseError: Firebase: Error (auth/invalid-api-key)
Why do I have the error that it says invalid API keys?为什么我有错误提示无效 API 密钥?
This is the sample .env.local
这是示例.env.local
REACT_APP_apiKey=AI**************JmXMKaFQQQrRzp4Q
REACT_APP_authDomain=sample-258a7.firebaseapp.com
REACT_APP_projectId=sample-258a7
REACT_APP_storageBucket=sample-258a7.appspot.com
REACT_APP_messagingSendearId=
REACT_APP_appId=1:1014069435807:web:04390779a92d4e3a4fb1aa
In another file:在另一个文件中:
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import { getAuth, GoogleAuthProvider, onAuthStateChanged } from "firebase/auth";
project under its own project settings
const firebaseConfig = {
apiKey: process.env.REACT_APP_apiKey,
authDomain: process.env.REACT_APP_authDomain,
projectId: process.env.REACT_APP_projectId,
storageBucket: process.env.REACT_APP_storageBucket,
messagingSenderId: process.env.REACT_APP_messagingSenderId,
appId: process.env.REACT_APP_appId,
};
//Initializing Firebase
const app = initializeApp(firebaseConfig);
This is the error:这是错误:
The Package.json: Package.json:
Make sure your .env.local
is placed in the root directory, and not in any subfolders like src
or public
.确保您的.env.local
放在根目录中,而不是放在任何子文件夹中,例如src
或public
。 Other than that, nothing seems to be wrong with your code.除此之外,您的代码似乎没有任何问题。 Just to be safe, cross check your API key with firebase.为了安全起见,请使用 firebase 交叉检查您的 API 密钥。 PS There's no need to hide your firebase public API key, its going to be visible in your app to the general public anyway. PS 无需隐藏您的 firebase 公共 API 密钥,无论如何它都会在您的应用程序中对公众可见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.