Home > Software design >  How can I fixed my problem"FirebaseError: Firebase: Error (auth/invalid-api-key)."
How can I fixed my problem"FirebaseError: Firebase: Error (auth/invalid-api-key)."

Time:05-07

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)"

CodePudding user response:

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

CodePudding user response:

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.

  • Related