From b88d5fbabfb6c0dddddb3a806292b74b0d627816 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 15 Jan 2026 11:28:57 -0500 Subject: [PATCH] Fixes for username and password sign in! Quick save while Gemini still working. --- src/lib/ae_core/ae_core__person.ts | 8 ++-- src/lib/ae_core/core__user.ts | 42 +++++++++++++++++-- .../app_components/e_app_sign_in_out.svelte | 32 +++++++++----- 3 files changed, 63 insertions(+), 19 deletions(-) diff --git a/src/lib/ae_core/ae_core__person.ts b/src/lib/ae_core/ae_core__person.ts index bc865c40..f8176ad8 100644 --- a/src/lib/ae_core/ae_core__person.ts +++ b/src/lib/ae_core/ae_core__person.ts @@ -115,15 +115,15 @@ export async function load_ae_obj_li__person({ } if (enabled === 'enabled') { - search_query.and.push({ field: 'enabled', op: 'eq', value: true }); + search_query.and.push({ field: 'enable', op: 'eq', value: true }); } else if (enabled === 'not_enabled') { - search_query.and.push({ field: 'enabled', op: 'eq', value: false }); + search_query.and.push({ field: 'enable', op: 'eq', value: false }); } if (hidden === 'hidden') { - search_query.and.push({ field: 'hidden', op: 'eq', value: true }); + search_query.and.push({ field: 'hide', op: 'eq', value: true }); } else if (hidden === 'not_hidden') { - search_query.and.push({ field: 'hidden', op: 'eq', value: false }); + search_query.and.push({ field: 'hide', op: 'eq', value: false }); } promise = api.search_ae_obj_v3({ diff --git a/src/lib/ae_core/core__user.ts b/src/lib/ae_core/core__user.ts index 2ce615c0..99538c99 100644 --- a/src/lib/ae_core/core__user.ts +++ b/src/lib/ae_core/core__user.ts @@ -33,6 +33,14 @@ export async function auth_ae_obj__username_password({ const endpoint = '/user/authenticate'; + // Prepare API config with correct headers + const use_api_cfg = { ...api_cfg, headers: { ...api_cfg.headers } }; + if (account_id) { + use_api_cfg.headers['x-account-id'] = account_id; + delete use_api_cfg.headers['x-no-account-id']; + params['account_id'] = account_id; + } + if (null_account_id) { params['null_account_id'] = true; } @@ -45,7 +53,7 @@ export async function auth_ae_obj__username_password({ ae_promises.auth__username_password = await api .get_object({ - api_cfg: api_cfg, + api_cfg: use_api_cfg, endpoint: endpoint, params: params, // data: {}, @@ -103,6 +111,14 @@ export async function auth_ae_obj__user_id_user_auth_key({ const endpoint = '/user/authenticate'; + // Prepare API config with correct headers + const use_api_cfg = { ...api_cfg, headers: { ...api_cfg.headers } }; + if (account_id) { + use_api_cfg.headers['x-account-id'] = account_id; + delete use_api_cfg.headers['x-no-account-id']; + params['account_id'] = account_id; + } + params['user_id'] = user_id; // Required params['auth_key'] = user_auth_key; // Required params['inc_jwt'] = true; // Request a JWT in the response @@ -112,7 +128,7 @@ export async function auth_ae_obj__user_id_user_auth_key({ ae_promises.auth__user_id_user_key = await api .get_object({ - api_cfg: api_cfg, + api_cfg: use_api_cfg, endpoint: endpoint, params: params, log_lvl: log_lvl @@ -170,8 +186,17 @@ export async function send_email_auth_ae_obj__user_id({ root_url: base_url, key_param_name: key_param_name }; + + // Prepare API config with correct headers + const use_api_cfg = { ...api_cfg, headers: { ...api_cfg.headers } }; + if (account_id) { + use_api_cfg.headers['x-account-id'] = account_id; + delete use_api_cfg.headers['x-no-account-id']; + params['account_id'] = account_id; + } + ae_promises.auth_key__send_email = await api.get_object({ - api_cfg: api_cfg, + api_cfg: use_api_cfg, endpoint: email_auth_key_endpoint, params: params, log_lvl: log_lvl @@ -246,15 +271,24 @@ export async function qry_ae_obj_li__user_email({ const endpoint = '/user/lookup_email'; + // Prepare API config with correct headers + const use_api_cfg = { ...api_cfg, headers: { ...api_cfg.headers } }; + if (account_id) { + use_api_cfg.headers['x-account-id'] = account_id; + delete use_api_cfg.headers['x-no-account-id']; + params['account_id'] = account_id; + } + params['email'] = email; // Required params['null_account_id'] = null_account_id || false; + if (log_lvl > 1) { console.log(`qry_ae_obj_li__user_email() - params:`, params); } ae_promises.qry__user_email = await api .get_object({ - api_cfg: api_cfg, + api_cfg: use_api_cfg, endpoint: endpoint, params: params, log_lvl: log_lvl 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 cf6e8d86..f03d5336 100644 --- a/src/lib/app_components/e_app_sign_in_out.svelte +++ b/src/lib/app_components/e_app_sign_in_out.svelte @@ -220,7 +220,7 @@ handle_send_auth_email({ user_id: user_response.user_id_random }); - } else if (user_response.length > 0) { + } else if (user_response && user_response.length > 0) { console.log(`Multiple users found for email:`, user_response); handle_send_auth_email({ user_id: user_response[0].user_id_random @@ -452,7 +452,7 @@ }) .then((user_response) => { // console.log(`HERE:`, user_response); - if (user_response.user_id_random) { + if (user_response?.user_id_random) { console.log( `Successfully authenticated in with User ID and User Auth Key: ${user_response.username}`, user_response @@ -461,7 +461,7 @@ user_id = user_obj.user_id_random; // Use the user_id_random for further API calls // person_id = user_obj.person_id_random; } else { - alert('Failed to authenticate: ' + user_response.error); + alert('Failed to authenticate: ' + (user_response?.error || 'Unknown error')); } }) .then((response) => { @@ -494,12 +494,18 @@ for_obj_type: 'account', for_obj_id: $ae_loc.account_id, qry_user_id: user_id, // The user_id_random from the above authentication + enabled: 'all', + hidden: 'all', // params_json: params_json, // params: params, log_lvl: 1 }) .then((person_response) => { - if (person_response[0].person_id_random) { + if ( + person_response && + person_response.length > 0 && + person_response[0].person_id_random + ) { console.log( `Successfully loaded person for user_id_random (${user_id}):`, person_response[0] @@ -510,8 +516,7 @@ trigger = true; // Set trigger to true to indicate we can now sign in } else { alert( - 'Failed to load person information: ' + - person_response.error + 'Failed to load person information. No person record found for this user.' ); } }) @@ -550,7 +555,7 @@ log_lvl: 1 }) .then((user_response) => { - if (user_response.user_id_random) { + if (user_response?.user_id_random) { console.log( `Successfully authenticated in with Username (${user_response.username}) and Password:`, user_response @@ -559,7 +564,7 @@ user_id = user_obj.user_id_random; // Use the user_id_random for further API calls // person_id = user_obj.person_id_random; } else { - alert('Failed to authenticate: ' + user_response.error); + alert('Failed to authenticate: ' + (user_response?.error || 'Unknown error')); } }) .then((response) => { @@ -592,12 +597,18 @@ for_obj_type: 'account', for_obj_id: $ae_loc.account_id, qry_user_id: user_id, // The user_id_random from the above authentication + enabled: 'all', + hidden: 'all', // params_json: params_json, // params: params, log_lvl: 1 }) .then((person_response) => { - if (person_response[0].person_id_random) { + if ( + person_response && + person_response.length > 0 && + person_response[0].person_id_random + ) { console.log( `Successfully loaded person for user_id_random (${user_id}):`, person_response[0] @@ -608,8 +619,7 @@ trigger = true; // Set trigger to true to indicate we can now sign in } else { alert( - 'Failed to load person information: ' + - person_response.error + 'Failed to load person information. No person record found for this user.' ); } })