I have a shell script to launch my react app that prompts the users for a firebase api key. The script then writes to a file that stores the key:
//api.js (script written file)
export const fireApiKey = "AIz...............................";
Then that file is imported and used in my firebase config file:
import { fireApiKey } from "../api";
.
.
.
const firebaseConfig = {
apiKey: fireApiKey,
authDomain: "name-3333.firebaseapp.com",
projectId: "name-3333",
storageBucket: "name-3333.appspot.com",
messagingSenderId: "3333333333",
appId: "333333333",
measurementId: "G-333333"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
export const provider = new GoogleAuthProvider();
export const db = getFirestore(app)
const analytics = getAnalytics(app);
I've attempted to try catch the initializeApp function call, but it seems even if the API key is incorrect this call still succeeds so the code that was in my catch block never was executed, but it did print an error to browser console: "GET https://firebase.googleapis.com/... 400 (Bad Request)".
If the users enters an incorrect key how do I handle/catch this error? I mostly want to just notify the user of this error.