Refactor login button event listener handling
This commit is contained in:
parent
8d54d27baa
commit
b50466f24f
1 changed files with 17 additions and 17 deletions
34
login.js
34
login.js
|
|
@ -7,22 +7,22 @@ const app = initializeApp(firebaseConfig);
|
||||||
const auth = getAuth(app);
|
const auth = getAuth(app);
|
||||||
|
|
||||||
// Håndter klikk
|
// Håndter klikk
|
||||||
document.getElementById('btn-login').addEventListener('click', async () => {
|
const loginBtn = document.getElementById('btn-login');
|
||||||
const btn = document.getElementById('btn-login');
|
if (loginBtn) {
|
||||||
const msg = document.getElementById('error-msg');
|
loginBtn.addEventListener('click', async () => {
|
||||||
|
const msg = document.getElementById('error-msg');
|
||||||
btn.textContent = "Autentiserer...";
|
|
||||||
msg.textContent = "";
|
|
||||||
|
|
||||||
try {
|
|
||||||
await signInAnonymously(auth);
|
|
||||||
|
|
||||||
// Suksess -> Gå til hovedsiden (Røsstad.html)
|
loginBtn.textContent = "Autentiserer...";
|
||||||
window.location.href = "Røsstad.html";
|
msg.textContent = "";
|
||||||
|
|
||||||
} catch (error) {
|
try {
|
||||||
console.error(error);
|
await signInAnonymously(auth);
|
||||||
msg.textContent = "Feil: " + error.message;
|
// Suksess -> Gå til hovedsiden
|
||||||
btn.textContent = "Prøv igjen";
|
window.location.href = "Røsstad.html";
|
||||||
}
|
} catch (error) {
|
||||||
});
|
console.error(error);
|
||||||
|
msg.textContent = "Feil: " + error.message;
|
||||||
|
loginBtn.textContent = "Prøv igjen";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue