fix: improve sign-in error messages for both auth flows
- Check user_response?.detail (FastAPI standard) before user_response?.error - Distinguish null response (network/server error) from bad credentials - Remove silent console.error-only path; user now always sees a message - Fix misleading 'auth_ae_obj__username_password' label in user_id+key flow - Clarify 'no person record' message to suggest contacting administrator - Simplify success log messages (remove dead commented-out code)
This commit is contained in:
@@ -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.'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user