diff --git a/src/lib/app_components/e_app_sign_in_out.svelte b/src/lib/app_components/e_app_sign_in_out.svelte index f52891c8..7f6a42d4 100644 --- a/src/lib/app_components/e_app_sign_in_out.svelte +++ b/src/lib/app_components/e_app_sign_in_out.svelte @@ -477,16 +477,18 @@ user_obj = user_response; // Store the user object for later use user_id = user_obj.user_id; // Use the user_id for further API calls // person_id = user_obj.person_id_random; + } else if (!user_response) { + alert('Sign in failed: No response from the server. Check your connection and try again.'); } else { - alert('Failed to authenticate: ' + (user_response?.error || 'Unknown error')); + // API returns 'detail' for validation errors (FastAPI standard), 'error' for app-level errors + const reason = user_response?.detail || user_response?.error || 'Invalid User ID or Auth Key.'; + alert('Sign in failed: ' + reason); } }) .then((response) => { if (!user_id) { - // If we didn't get a user_id, return early - console.error( - 'No user_id obtained from auth_ae_obj__username_password' - ); + // Auth failed in the previous .then() — user has already been alerted + console.error('Auth (user_id+key): user_id not set after authentication attempt.'); return; } @@ -537,27 +539,17 @@ trigger = true; // Set trigger to true to indicate we can now sign in } else { alert( - 'Failed to load person information. No person record found for this user.' + 'Sign in failed: No person record is linked to this user account. Please contact your administrator.' ); } }) .then(() => { // Once all promises are resolved, we can check if we have both user_id and person_id if (user_id && person_id) { - // Set the session information - // $ae_loc.person_id = person_id; // Set the person_id in the ae_loc store - // $ae_loc.person = person_obj; // Store the full person object for reference - // $ae_loc.user_id = user_id; // Set the user_id in the ae_loc store - // $ae_loc.user = user_obj; // Store the full user object for reference - - console.log(`Successfully authenticated and loaded user and person records: - user_id: ${user_id}, - person_id: ${person_id} - `); - // window.location.reload(); // Reload to get the new session + console.log(`Successfully authenticated and loaded user and person records: user_id: ${user_id}, person_id: ${person_id}`); } else { console.error( - 'Failed to authenticate and load data: missing user_id or person_id' + 'Auth (user_id+key): finished but missing user_id or person_id — sign_in() will not be called.' ); } }); @@ -584,16 +576,18 @@ user_obj = user_response; // Store the user object for later use user_id = user_obj.user_id; // Use the user_id for further API calls // person_id = user_obj.person_id_random; + } else if (!user_response) { + alert('Sign in failed: No response from the server. Check your connection and try again.'); } else { - alert('Failed to authenticate: ' + (user_response?.error || 'Unknown error')); + // API returns 'detail' for validation errors (FastAPI standard), 'error' for app-level errors + const reason = user_response?.detail || user_response?.error || 'Invalid username or password.'; + alert('Sign in failed: ' + reason); } }) .then((response) => { if (!user_id) { - // If we didn't get a user_id, return early - console.error( - 'No user_id obtained from auth_ae_obj__username_password' - ); + // Auth failed in the previous .then() — user has already been alerted + console.error('Auth (username+password): user_id not set after authentication attempt.'); return; } @@ -644,27 +638,17 @@ trigger = true; // Set trigger to true to indicate we can now sign in } else { alert( - 'Failed to load person information. No person record found for this user.' + 'Sign in failed: No person record is linked to this user account. Please contact your administrator.' ); } }) .then(() => { // Once all promises are resolved, we can check if we have both user_id and person_id if (user_id && person_id) { - // Set the session information - // $ae_loc.person_id = person_id; // Set the person_id in the ae_loc store - // $ae_loc.person = person_obj; // Store the full person object for reference - // $ae_loc.user_id = user_id; // Set the user_id in the ae_loc store - // $ae_loc.user = user_obj; // Store the full user object for reference - - console.log(`Successfully authenticated and loaded user and person records: - user_id: ${user_id}, - person_id: ${person_id} - `); - // window.location.reload(); // Reload to get the new session + console.log(`Successfully authenticated and loaded user and person records: user_id: ${user_id}, person_id: ${person_id}`); } else { console.error( - 'Failed to authenticate and load data: missing user_id or person_id' + 'Auth (username+password): finished but missing user_id or person_id — sign_in() will not be called.' ); } });