update some login things

This commit is contained in:
creations 2025-03-18 22:55:22 -04:00
parent a52be45907
commit b40c1db189
Signed by: creations
GPG key ID: 8F553AA4320FC711
7 changed files with 333 additions and 37 deletions

37
public/js/auth/login.js Normal file
View file

@ -0,0 +1,37 @@
const loginForm = document.getElementById("login-form");
const errorMessage = document.getElementById("error-message");
if (loginForm) {
loginForm.addEventListener("submit", async (e) => {
e.preventDefault();
const email = document.getElementById("email").value;
const password = document.getElementById("password").value;
try {
const response = await fetch("/api/auth/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: "same-origin",
body: JSON.stringify({ email, password }),
});
const data = await response.json();
if (data.success) {
window.location.href = "/";
} else {
errorMessage.style.display = "block";
errorMessage.textContent =
data.error ||
"Invalid email or password. Please try again.";
}
} catch (error) {
console.error("Login error:", error);
errorMessage.style.display = "block";
errorMessage.textContent = "An error occurred. Please try again.";
}
});
}