I have an application that is relying on firebase auth, and I’m getting an error stating “Cannot read properties of undefined (reading ‘settings)”. Nothing seems to be wrong on the server side, anyone know how to fix this?
Here’s my code:
import {initializeApp} from "https://www.gstatic.com/firebasejs/11.1.0/firebase-app.js";
import {
getAuth,
signInWithEmailAndPassword,
signOut,
} from "https://www.gstatic.com/firebasejs/11.1.0/firebase-auth.js";
const firebaseConfig = {
//correct config
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const form = document.querySelector("form");
window.addEventListener("beforeunload", (event) => {
// Check if you really want to prevent the refresh
if (confirm("Are you sure you want to leave this page?")) {
// Allow the refresh
} else {
// Prevent the refresh
event.preventDefault();
event.returnValue = ""; // Required for some browsers
}
});
async function login() {
const email = document.getElementById("username").value;
const password = document.getElementById("pw").value;
try {
const userCredential = await signInWithEmailAndPassword(email, password);
console.log(userCredential);
const idToken = await userCredential.user.getIdToken();
alert("signin function complete");
const response = await fetch("http://localhost:3000/auth/login", {
method: "POST",
credentials: "include",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ idToken }),
});
if (response.ok) {
alert("Logged in successfully!");
} else {
alert("Login failed: " + (await response.text()));
}
} catch (error) {
alert("Error: " + error.message);
console.error(error);
}
}
async function logout() {
await fetch("http://localhost:3000/logout", {
method: "POST",
credentials: "include",
});
alert("Logged out successfully!");
}
async function checkProfile() {
const response = await fetch("http://localhost:3000/profile", {
method: "GET",
credentials: "include",
});
if (response.ok) {
alert(await response.text());
} else {
alert("Access denied: " + (await response.text()));
}
}
window.login = login;
window.logout = logout;
window.checkProfile = checkProfile;
and the error:
enter image description here
TypeError: Cannot read properties of undefined (reading 'settings')
at _isFirebaseServerApp (internal.ts:173:37)
at signInWithEmailAndPassword (email_and_password.ts:352:7)
at login (login.js:37:36)
at HTMLButtonElement.onclick (home/:182:76)
I don’t think my config is wrong since i’ve used it in other parts. Anyone know a fix?
I tried reading other questions, but none of the fixes seem to work. I even switched the version to a previous version, and still didn’t work.