fix handleAuthSubmit

This commit is contained in:
chris 2025-08-10 09:31:24 -04:00
parent 0cabc5288e
commit 2c4ba19b71

View File

@ -23,22 +23,20 @@ let authToken = null;
// --- EVENT HANDLERS (The "Logic") --- // --- EVENT HANDLERS (The "Logic") ---
async function handleAuthSubmit(e) { async function handleAuthSubmit(e) {
console.log("1. Form submitted, handleAuthSubmit function started."); // Checkpoint 1
e.preventDefault(); e.preventDefault();
const username = e.target.elements.username.value; const username = e.target.elements.username.value;
const password = e.target.elements.password.value; const password = e.target.elements.password.value;
console.log(`2. Attempting to log in user: ${username}`); // Checkpoint 2
const res = await apiCall('/login', 'POST', { username, password }); const res = await apiCall('/login', 'POST', { username, password });
console.log("3. Received response from apiCall:", res); // Checkpoint 3
if (res && res.success) { if (res && res.success) {
console.log("4. Login was successful, calling initializeApp()."); // Checkpoint 4 // --- THIS IS THE FIX ---
initializeApp(); // You were missing these two lines to save the data
localStorage.setItem('authToken', res.data.token);
localStorage.setItem('user', JSON.stringify(res.data.user));
// --- END OF FIX ---
initializeApp(); // Now this will find the data it needs
} else { } else {
console.error("5. Login failed. Server response:", res); // Checkpoint 5
// We can add a user-facing error message here
showMessage(res?.data?.message || 'Login failed. Please check your credentials.', 'error'); showMessage(res?.data?.message || 'Login failed. Please check your credentials.', 'error');
} }
} }