fix handleAuthSubmit
This commit is contained in:
parent
0cabc5288e
commit
2c4ba19b71
@ -23,22 +23,20 @@ let authToken = null;
|
||||
|
||||
// --- EVENT HANDLERS (The "Logic") ---
|
||||
async function handleAuthSubmit(e) {
|
||||
console.log("1. Form submitted, handleAuthSubmit function started."); // Checkpoint 1
|
||||
e.preventDefault();
|
||||
|
||||
const username = e.target.elements.username.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 });
|
||||
console.log("3. Received response from apiCall:", res); // Checkpoint 3
|
||||
|
||||
if (res && res.success) {
|
||||
console.log("4. Login was successful, calling initializeApp()."); // Checkpoint 4
|
||||
initializeApp();
|
||||
// --- THIS IS THE FIX ---
|
||||
// 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 {
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user