Formatting + Added Home Page
This commit is contained in:
@@ -16,4 +16,24 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
logoutButton.addEventListener("click", async (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
const logoutRes = await fetch('/logout', {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
});
|
||||
|
||||
if (logoutRes.ok) {
|
||||
document.cookie = "authorization=; Max-Age=0; path=/;";
|
||||
window.location.href = "/login";
|
||||
} else {
|
||||
console.log("Failed to logout");
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("Logout error:", err);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const username = form.username.value;
|
||||
const password = form.password.value;
|
||||
const credentials = {username, password};
|
||||
|
||||
try {
|
||||
const loginRes = await fetch("/login", {
|
||||
method: "POST",
|
||||
@@ -17,7 +15,7 @@
|
||||
|
||||
if (loginRes.ok) {
|
||||
const loginData = await loginRes.json();
|
||||
alert(`Welcome back, ${loginData.username}!`);
|
||||
alert(`Welcome back, ${loginData.lower_username}!`);
|
||||
document.cookie = `authorization=${loginData.token}`
|
||||
window.location.href = "/";
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user