first commit
This commit is contained in:
commit
672f0deb6a
18 changed files with 1274 additions and 0 deletions
35
frontend/ts/login.ts
Normal file
35
frontend/ts/login.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { login } from "./api";
|
||||
|
||||
const form = document.querySelector("form")!;
|
||||
const passwordInput = document.getElementById("password") as HTMLInputElement;
|
||||
|
||||
const errorEl = document.createElement("p");
|
||||
errorEl.className = "text-red-500 mt-2 text-sm hidden";
|
||||
form.appendChild(errorEl);
|
||||
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
errorEl.classList.add("hidden");
|
||||
|
||||
const password = passwordInput.value.trim();
|
||||
if (!password) {
|
||||
errorEl.textContent = "Please enter a password.";
|
||||
errorEl.classList.remove("hidden");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await login(password);
|
||||
|
||||
if (res.success) {
|
||||
localStorage.setItem("password", password);
|
||||
window.location.href = "/dashboard.html";
|
||||
} else {
|
||||
errorEl.textContent = res.error || "Invalid password.";
|
||||
errorEl.classList.remove("hidden");
|
||||
}
|
||||
} catch {
|
||||
errorEl.textContent = "Network error. Please try again.";
|
||||
errorEl.classList.remove("hidden");
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue