0

My environment variable is ok. No comas and name mistakes but they given me error like "FirebaseError: Firebase: Error (auth/invalid-api-key)". How can I fixed it. Please Help me...

This my .env file

REACT_APP_apiKey=AIzaSyBWobnhbdeMdNpXXXXXXXXXXXXXXXXXXXX
REACT_APP_authDomain=XXXXX.firebaseapp.com
REACT_APP_projectId=XXXX
REACT_APP_storageBucket=XXXXX.appspot.com
REACT_APP_messagingSenderId=4997390XXXXX
REACT_APP_appId=1:4997390XXXXX:web:cc7bc80aa1bdb78fXXXXXX
REACT_APP_measurementId=G-M1XDXXXXXX

This my firebase config file

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,
  measurementId: process.env.REACT_APP_measurementId,
};

when I debugging firebaseConfig object

console.log(firebaseConfig.apiKey);  ==========> undefined 
console.log(firebaseConfig.authDomain);  ==========> undefined 
console.log(firebaseConfig.projectId);  ==========> undefined 
console.log(firebaseConfig.storageBucket); ==========> undefined 
console.log(firebaseConfig.measurementId); ==========> undefined 
console.log(firebaseConfig.appId); ==========> undefined 
console.log(firebaseConfig.measurementId); ==========> undefined 

client side given error this "FirebaseError: Firebase: Error (auth/invalid-api-key)"

  • Does this answer your question? https://stackoverflow.com/questions/49579028/adding-an-env-file-to-react-project#comment110254072_49579028 – Tanay May 07 '22 at 06:32
  • Hmm I see now my terminal restart again then my firebaseConfig object get that value..That's Awesome – Md Ataur Rahman May 07 '22 at 06:40

2 Answers2

0

When you get in undefined from firebaseConfig object value of keys. And they given a error like FirebaseError: Firebase: Error (auth/invalid-api-key). but your environment variable name and process.env.[environment variable name] and you had create a .env file root directory but stll they given same error.

The Answer is .. You have to do right now, your terminal again restart when you still the same error..

this solution is worked my problem.

-1

You should create the root file .env.local enter image description here

  • Yep ! I had created a .env file in root directory but still given me error. – Md Ataur Rahman May 07 '22 at 06:24
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 09 '22 at 13:31