Refactor login button event listener handling

This commit is contained in:
Anaru 2025-11-24 17:54:32 +01:00 committed by GitHub
parent 8d54d27baa
commit b50466f24f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,22 +7,22 @@ const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
// Håndter klikk
document.getElementById('btn-login').addEventListener('click', async () => {
const btn = document.getElementById('btn-login');
const msg = document.getElementById('error-msg');
const loginBtn = document.getElementById('btn-login');
if (loginBtn) {
loginBtn.addEventListener('click', async () => {
const msg = document.getElementById('error-msg');
btn.textContent = "Autentiserer...";
msg.textContent = "";
loginBtn.textContent = "Autentiserer...";
msg.textContent = "";
try {
await signInAnonymously(auth);
// Suksess -> Gå til hovedsiden (Røsstad.html)
window.location.href = "Røsstad.html";
} catch (error) {
console.error(error);
msg.textContent = "Feil: " + error.message;
btn.textContent = "Prøv igjen";
}
});
try {
await signInAnonymously(auth);
// Suksess -> Gå til hovedsiden
window.location.href = "Røsstad.html";
} catch (error) {
console.error(error);
msg.textContent = "Feil: " + error.message;
loginBtn.textContent = "Prøv igjen";
}
});
}