Yoster Daniel
Yoster Daniel

Reputation: 21

Getting this error Firebase Error (auth/invalid-api-key)

Im getting the error 'Firebase: Error (auth/invalid-api-key) ' even though all my authentication values were correct.

Upvotes: 0

Views: 538

Answers (1)

Yoster Daniel
Yoster Daniel

Reputation: 21

  1. Create a separate file called 'firebase.config.js'. In the file, only have an 'export const' variable with the credentials for the firebase. Here is my file:
export const firebaseConfig = {
    apiKey: process.env.NEXT_PUBLIC_API_KEY,
    authDomain: process.env.NEXT_PUBLIC_AUTH_DOMAIN,
    projectId: process.env.NEXT_PUBLIC_PROJECT_ID,
    storageBucket: process.env.NEXT_PUBLIC_STORAGE_BUCKET,
    messagingSenderId: process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID,
    appId: process.env.NEXT_PUBLIC_APP_ID,
    measurementId: process.env.NEXT_PUBLIC_MEAUREMENT_ID 
  
  };
  1. Go back to 'firebase.js' file, remove credentials from there, then reference the recently created variable from file with this line
import { firebaseConfig } from './firebase.config';
  1. Finally, Initialize the Firebase shown below
const app = initializeApp(firebaseConfig);
export const auth = getAuth();
export const db = getFirestore(app);

Upvotes: 1

Related Questions