Authenticatoin Implementation

This commit is contained in:
2026-01-27 09:48:58 -05:00
parent 6e3f8b46a5
commit 4ae3a9eb17
17 changed files with 535 additions and 9 deletions

View File

@@ -8,7 +8,9 @@ const CONFIG_FIELDS = {
"REASSIGN_DELAY": "reassign-delay",
"ASSIGNMENT_TIMEOUT": "assignment-timeout",
"ASSIGNMENT_REMINDER": "assignment-reminder",
"CHAIN_TIMER_THRESHOLD": "chain-timer-threshold"
"CHAIN_TIMER_THRESHOLD": "chain-timer-threshold",
"AUTH_PASSWORD": "auth-password",
"JWT_SECRET": "jwt-secret"
};
let sensitiveFields = [];
@@ -43,8 +45,11 @@ async function loadConfig() {
}
async function saveConfigValue(key) {
console.log("saveConfigValue called with key:", key);
const inputId = CONFIG_FIELDS[key];
console.log("Input ID:", inputId);
const input = document.getElementById(inputId);
console.log("Input element:", input);
if (!input) {
console.error("Input not found:", inputId);
@@ -52,13 +57,17 @@ async function saveConfigValue(key) {
}
let value = input.value.trim();
console.log("Value to save:", value);
// Don't save if sensitive field is empty (means user didn't change it)
if (sensitiveFields.includes(key) && value === "") {
console.log("No changes to save - field is empty");
alert("No changes to save");
return;
}
console.log("Proceeding with save...");
// Convert to number if needed
if (input.type === "number") {
value = parseInt(value);
@@ -69,11 +78,13 @@ async function saveConfigValue(key) {
}
try {
console.log("Sending API request to /api/config with:", { key, value });
const res = await fetch("/api/config", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ key, value })
});
console.log("API response status:", res.status);
if (!res.ok) {
console.error("Save failed:", res.status);
@@ -94,12 +105,41 @@ async function saveConfigValue(key) {
}
function wireUp() {
console.log("wireUp called");
// Attach save handlers to all save buttons
const saveButtons = document.querySelectorAll(".config-save-btn");
console.log("Found save buttons:", saveButtons.length);
saveButtons.forEach(btn => {
const key = btn.dataset.key;
console.log("Attaching handler for key:", key);
btn.addEventListener("click", () => saveConfigValue(key));
});
// Attach logout handler
const logoutBtn = document.getElementById("logout-btn");
if (logoutBtn) logoutBtn.addEventListener("click", handleLogout);
}
async function handleLogout() {
console.log("handleLogout called");
try {
console.log("Sending logout request to /auth/logout");
const response = await fetch("/auth/logout", {
method: "POST"
});
console.log("Logout response status:", response.status);
if (response.ok) {
console.log("Logout successful, redirecting to /login");
window.location.href = "/login";
} else {
console.error("Logout failed with status:", response.status);
window.location.href = "/login";
}
} catch (error) {
console.error("Error during logout:", error);
window.location.href = "/login";
}
}
document.addEventListener("DOMContentLoaded", async () => {

View File

@@ -730,10 +730,41 @@ function wireUp() {
const resetBtn = document.getElementById("reset-groups-btn");
if (resetBtn) resetBtn.addEventListener("click", resetGroups);
const logoutBtn = document.getElementById("logout-btn");
if (logoutBtn) logoutBtn.addEventListener("click", handleLogout);
setupDropZones();
console.log(">>> wireUp completed");
}
// ---------------------------
// Logout handler
// ---------------------------
async function handleLogout() {
console.log("handleLogout called");
try {
console.log("Sending logout request to /auth/logout");
const response = await fetch("/auth/logout", {
method: "POST"
});
console.log("Logout response status:", response.status);
if (response.ok) {
console.log("Logout successful, redirecting to /login");
// Redirect to login page
window.location.href = "/login";
} else {
console.error("Logout failed with status:", response.status);
// Still redirect to login page
window.location.href = "/login";
}
} catch (error) {
console.error("Error during logout:", error);
// Still redirect to login page
window.location.href = "/login";
}
}
// ---------------------------
// Initial load
// ---------------------------