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 92a3f89a..13e02895 100644 --- a/src/lib/app_components/e_app_sign_in_out.svelte +++ b/src/lib/app_components/e_app_sign_in_out.svelte @@ -233,12 +233,18 @@ function handle_send_auth_email({ user_id }: { user_id: string }) { console.log($ae_loc.hostname); // URL hostname // This function creates a new auth_key and then sends an email to the user with the new auth key. + // WHY: root_url is required by the backend email builder — if null/undefined it + // produces a broken link ("None?user_id=..."). Fall back to window.location.origin + // in case $ae_loc.base_url is not yet set when this fires. + const magic_link_root_url = + $ae_loc.base_url || (browser ? window.location.origin : ''); + ae_promises.send_email_auth_ae_obj__user_id = core_func.send_email_auth_ae_obj__user_id({ api_cfg: $ae_api, account_id: $slct.account_id, user_id: user_id, - base_url: $ae_loc.base_url, + base_url: magic_link_root_url, log_lvl: 0 }); } @@ -256,17 +262,9 @@ function handle_lookup_user_email({ email }: { email: string }) { log_lvl: 0 }) .then((user_response) => { - if (user_response?.user_id_random) { + if (user_response?.user_id) { console.log(`User found for email:`, user_response); - handle_send_auth_email({ - user_id: user_response.user_id_random - }); - email_send_status = 'sent'; - } 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 - }); + handle_send_auth_email({ user_id: user_response.user_id }); email_send_status = 'sent'; } else { console.warn('No user found for email:', email); @@ -324,19 +322,12 @@ async function handle_change_password() { log_lvl: 0 }); - if (!ae_promises.load__user_obj_li) { - // This means a 404 was returned + if (!ae_promises.load__user_obj_li?.user_id) { alert('No user found with that email address.'); return; - } else if (ae_promises.load__user_obj_li?.user_id_random) { + } else { console.log(`User found for email:`, ae_promises.load__user_obj_li); - use_user_id = ae_promises.load__user_obj_li.user_id_random; - } else if (ae_promises.load__user_obj_li.length > 0) { - console.log( - `Multiple users found for email:`, - ae_promises.load__user_obj_li - ); - use_user_id = ae_promises.load__user_obj_li[0].user_id_random; + use_user_id = ae_promises.load__user_obj_li.user_id; } } else { wait_for_lookup = false;