From 2c3c997f396759e2d6abfbb05b9141857b8e6811 Mon Sep 17 00:00:00 2001 From: userAdityaa Date: Sat, 18 Apr 2026 03:41:40 +0545 Subject: [PATCH] chore: carify Pomade login errors with actionable invalid vs network messaging --- src/app/components/LogInEmail.svelte | 12 ++++++++++-- src/app/components/LogInOTP.svelte | 12 +++++++++++- src/app/components/LogInOTPConfirm.svelte | 16 ++++++++++++---- src/app/components/LogInSelect.svelte | 10 +++++++++- src/app/util/pomadeErrors.ts | 11 +++++++++++ src/routes/settings/profile/+page.svelte | 14 +++++++++++++- 6 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 src/app/util/pomadeErrors.ts diff --git a/src/app/components/LogInEmail.svelte b/src/app/components/LogInEmail.svelte index 597ad074..eecc9042 100644 --- a/src/app/components/LogInEmail.svelte +++ b/src/app/components/LogInEmail.svelte @@ -19,6 +19,7 @@ import LogInOTP from "@app/components/LogInOTP.svelte" import LogInSelect from "@app/components/LogInSelect.svelte" import {deleteDeactivatedPomadeSessions, loginWithPomade} from "@app/util/pomade" + import {getPomadeLoginFailureMessage, POMADE_NETWORK_ERROR_MESSAGE} from "@app/util/pomadeErrors" import {pushModal, clearModals} from "@app/util/modal" import {setChecked} from "@app/util/notifications" import {pushToast} from "@app/util/toast" @@ -44,7 +45,7 @@ return pushToast({ theme: "error", - message: "Sorry, we were unable to log you in.", + message: getPomadeLoginFailureMessage(messages), }) } @@ -64,10 +65,17 @@ pushToast({ theme: "error", - message: "Sorry, we were unable to log you in.", + message: getPomadeLoginFailureMessage(res.messages), }) } } + } catch (error) { + console.error("Login error:", error) + + pushToast({ + theme: "error", + message: POMADE_NETWORK_ERROR_MESSAGE, + }) } finally { loading = false } diff --git a/src/app/components/LogInOTP.svelte b/src/app/components/LogInOTP.svelte index b0d71e19..a5658e5d 100644 --- a/src/app/components/LogInOTP.svelte +++ b/src/app/components/LogInOTP.svelte @@ -15,6 +15,7 @@ import ModalSubtitle from "@lib/components/ModalSubtitle.svelte" import ModalFooter from "@lib/components/ModalFooter.svelte" import LogInOTPConfirm from "@app/components/LogInOTPConfirm.svelte" + import {POMADE_NETWORK_ERROR_MESSAGE} from "@app/util/pomadeErrors" import {pushModal} from "@app/util/modal" import {pushToast} from "@app/util/toast" @@ -35,11 +36,20 @@ if (ok) { pushModal(LogInOTPConfirm, {email, peersByPrefix}) } else { + console.error("Pomade challenge request failed during OTP login") + pushToast({ theme: "error", - message: "Sorry, we were unable to request a login code.", + message: POMADE_NETWORK_ERROR_MESSAGE, }) } + } catch (error) { + console.error(error) + + pushToast({ + theme: "error", + message: POMADE_NETWORK_ERROR_MESSAGE, + }) } finally { loading = false } diff --git a/src/app/components/LogInOTPConfirm.svelte b/src/app/components/LogInOTPConfirm.svelte index d0ce449a..4b16a49f 100644 --- a/src/app/components/LogInOTPConfirm.svelte +++ b/src/app/components/LogInOTPConfirm.svelte @@ -15,10 +15,11 @@ import ModalFooter from "@lib/components/ModalFooter.svelte" import StringMultiInput from "@lib/components/StringMultiInput.svelte" import LogInSelect from "@app/components/LogInSelect.svelte" - import {pushToast} from "@app/util/toast" - import {setChecked} from "@app/util/notifications" import {pushModal, clearModals} from "@app/util/modal" + import {setChecked} from "@app/util/notifications" import {deleteDeactivatedPomadeSessions, loginWithPomade} from "@app/util/pomade" + import {getPomadeLoginFailureMessage, POMADE_NETWORK_ERROR_MESSAGE} from "@app/util/pomadeErrors" + import {pushToast} from "@app/util/toast" type Props = { email: string @@ -44,7 +45,7 @@ return pushToast({ theme: "error", - message: "Sorry, we were unable to log you in.", + message: getPomadeLoginFailureMessage(messages), }) } @@ -64,10 +65,17 @@ pushToast({ theme: "error", - message: "Sorry, we were unable to log you in.", + message: getPomadeLoginFailureMessage(res.messages), }) } } + } catch (error) { + console.error("Login error:", error) + + pushToast({ + theme: "error", + message: POMADE_NETWORK_ERROR_MESSAGE, + }) } finally { loading = false } diff --git a/src/app/components/LogInSelect.svelte b/src/app/components/LogInSelect.svelte index 9da7c432..8d416afd 100644 --- a/src/app/components/LogInSelect.svelte +++ b/src/app/components/LogInSelect.svelte @@ -14,6 +14,7 @@ import ModalFooter from "@lib/components/ModalFooter.svelte" import Profile from "@app/components/Profile.svelte" import {deleteDeactivatedPomadeSessions, loginWithPomade} from "@app/util/pomade" + import {getPomadeLoginFailureMessage, POMADE_NETWORK_ERROR_MESSAGE} from "@app/util/pomadeErrors" import {setChecked} from "@app/util/notifications" import {clearModals} from "@app/util/modal" import {pushToast} from "@app/util/toast" @@ -46,9 +47,16 @@ pushToast({ theme: "error", - message: "Sorry, we were unable to log you in.", + message: getPomadeLoginFailureMessage(res.messages), }) } + } catch (error) { + console.error("Login error:", error) + + pushToast({ + theme: "error", + message: POMADE_NETWORK_ERROR_MESSAGE, + }) } finally { loading = false } diff --git a/src/app/util/pomadeErrors.ts b/src/app/util/pomadeErrors.ts new file mode 100644 index 00000000..595e1b73 --- /dev/null +++ b/src/app/util/pomadeErrors.ts @@ -0,0 +1,11 @@ +export const POMADE_INVALID_LOGIN_MESSAGE = "Invalid login information" +export const POMADE_NETWORK_ERROR_MESSAGE = "Network error, please try again" + +type PomadeMessage = { + res?: unknown +} + +export const getPomadeLoginFailureMessage = (messages: PomadeMessage[]) => + messages.some(message => message.res !== undefined) + ? POMADE_INVALID_LOGIN_MESSAGE + : POMADE_NETWORK_ERROR_MESSAGE diff --git a/src/routes/settings/profile/+page.svelte b/src/routes/settings/profile/+page.svelte index 4fb05e09..79c49087 100644 --- a/src/routes/settings/profile/+page.svelte +++ b/src/routes/settings/profile/+page.svelte @@ -27,6 +27,7 @@ import PasswordReset from "@app/components/PasswordReset.svelte" import InfoKeys from "@app/components/InfoKeys.svelte" import {pushModal} from "@app/util/modal" + import {POMADE_NETWORK_ERROR_MESSAGE} from "@app/util/pomadeErrors" import {clip, pushToast} from "@app/util/toast" const npub = nip19.npubEncode($pubkey!) @@ -48,13 +49,24 @@ const {ok, peersByPrefix} = await Client.requestChallenge($session!.email) if (!ok) { + console.error("Pomade challenge request failed during password reset initiation") + pushToast({ theme: "error", - message: "Failed to initiate password reset!", + message: POMADE_NETWORK_ERROR_MESSAGE, }) + + return } pushModal(PasswordReset, {peersByPrefix}) + } catch (error) { + console.error(error) + + pushToast({ + theme: "error", + message: POMADE_NETWORK_ERROR_MESSAGE, + }) } finally { loading = false } -- 2.52.0