Reputation: 711
I have my API key stored in a local .env file in my React project, and it is correctly pasted directly from my firebase console setup page. However, I receive this error:
Firebase: Error (auth/invalid-api-key).
createErrorInternal
D:/src/core/util/assert.ts:101
98 | );
99 | }
100 |
> 101 | return _DEFAULT_AUTH_ERROR_FACTORY.create(
| ^ 102 | authOrCode,
103 | ...(rest as AuthErrorListParams<K>)
104 | );
I don't see why React is giving me an error. I initialized Firebase in the following file:
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
const firebaseConfig = {
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.REACT_APP_FIREBASE_APP_ID,
};
const app = initializeApp(firebaseConfig);
export const auth = getAuth();
export default app;
Upvotes: 12
Views: 9131
Reputation: 11
You can restart yours react app by clicking npm start in CMD. The same things happened to me after setting the environment variable. Hopefully, that will work.
Upvotes: 1
Reputation: 65
this problem occurs because , you might have written your env file in wrong way like this
// Wrong:
REACT_APP_FIREBASE_KEY=”AHEHEHR”
// Right:
REACT_APP_FIREBASE_KEY=AHEHEHR
you don't have use any trailing comma or quotes , after or around you api key ,and after making changes to your env file you have to restart server
Upvotes: 3
Reputation: 317
It seems your env
variables are invalid.
You can check a few things though.
env
variables.env
variable names are correct.env
file is in root folder means it should be with your your src
and public
folder. Upvotes: 5