Why do I have the error that it says invalid API keys?
This is the sample .env.local
JavaScript
x
7
1
REACT_APP_apiKey=AI**************JmXMKaFQQQrRzp4Q
2
REACT_APP_authDomain=sample-258a7.firebaseapp.com
3
REACT_APP_projectId=sample-258a7
4
REACT_APP_storageBucket=sample-258a7.appspot.com
5
REACT_APP_messagingSendearId=
6
REACT_APP_appId=1:1014069435807:web:04390779a92d4e3a4fb1aa
7
In another file:
JavaScript
1
18
18
1
import { initializeApp } from "firebase/app";
2
import { getFirestore } from "firebase/firestore";
3
import { getAuth, GoogleAuthProvider, onAuthStateChanged } from "firebase/auth";
4
5
project under its own project settings
6
const firebaseConfig = {
7
8
apiKey: process.env.REACT_APP_apiKey,
9
authDomain: process.env.REACT_APP_authDomain,
10
projectId: process.env.REACT_APP_projectId,
11
storageBucket: process.env.REACT_APP_storageBucket,
12
messagingSenderId: process.env.REACT_APP_messagingSenderId,
13
appId: process.env.REACT_APP_appId,
14
};
15
16
//Initializing Firebase
17
const app = initializeApp(firebaseConfig);
18
This is the error:
The Package.json:
Advertisement
Answer
Make sure your .env.local
is placed in the root directory, and not in any subfolders like src
or public
. Other than that, nothing seems to be wrong with your code. Just to be safe, cross check your API key with firebase.
P.S. There’s no need to hide your firebase public API key, its going to be visible in your app to the general public anyway.