In a react firebase project I am getting the error = " firebase: error (auth/api-key-not-valid.-please-pass-a-valid-api-key.)" Why am I getting this error?
Here is my firebase initializing code:
import { initializeApp } from "firebase/app";
import { getAuth } from 'firebase/auth';
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey:process.env.REACT_APP_authDomain,
authDomain:process.env.REACT_APP_apiKey,
projectId:process.env.REACT_APP_projectId,
storageBucket:process.env.REACT_APP_storageBucket,
messagingSenderId:process.env.REACT_APP_messagingSenderId,
appId:process.env.REACT_APP_appId
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
export default auth;
In the .env file where you put all the firebase given api keys put those keys in a formate like below. No extra punctuation.
REACT_APP_authDomain = YOUR_FIREBASE_KEY
Check all the api keys are OK
If all things are OK. Stop your 'react hotreload' and start your react app again by 'npm start'
At last I am seeing that you are providing wrong value for keys. You have provided 'apikey' the 'REACT_APP_authDomain' value and authDomain the 'REACT_APP_apiKey' value. Check that also. Good luck 🤞.
apiKey:process.env.REACT_APP_authDomain,
authDomain:process.env.REACT_APP_apiKey