From 95c5e7399659dd35538e63c7abdc424e87c6c25f Mon Sep 17 00:00:00 2001 From: Jip Fr Date: Sun, 10 Dec 2023 22:10:37 +0100 Subject: [PATCH] Better error for unknown account Co-authored-by: mrjvs --- src/assets/locales/en.json | 2 +- src/assets/locales/pirate.json | 2 +- src/pages/parts/auth/LoginFormPart.tsx | 20 ++++++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json index 71fb1d78..90d6e56b 100644 --- a/src/assets/locales/en.json +++ b/src/assets/locales/en.json @@ -17,7 +17,7 @@ "login": { "title": "Login to your account", "description": "Please enter your passphrase to login to your account", - "validationError": "Invalid or incomplete passphrase", + "validationError": "Incorrect or incomplete passphrase", "deviceLengthError": "Please enter a device name", "submit": "Login", "passphraseLabel": "12-Word passphrase", diff --git a/src/assets/locales/pirate.json b/src/assets/locales/pirate.json index b0048e82..0abcc5d5 100644 --- a/src/assets/locales/pirate.json +++ b/src/assets/locales/pirate.json @@ -16,7 +16,7 @@ "passphrasePlaceholder": "Passphrase", "submit": "Hoist Anchor", "title": "Hoist the Jolly Roger", - "validationError": "Arr, invalid or incomplete passphrase" + "validationError": "Arr, incorrect or incomplete passphrase" }, "register": { "information": { diff --git a/src/pages/parts/auth/LoginFormPart.tsx b/src/pages/parts/auth/LoginFormPart.tsx index d87f6e14..1ff43422 100644 --- a/src/pages/parts/auth/LoginFormPart.tsx +++ b/src/pages/parts/auth/LoginFormPart.tsx @@ -1,6 +1,7 @@ import { useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { useAsyncFn } from "react-use"; +import type { AsyncReturnType } from "type-fest"; import { verifyValidMnemonic } from "@/backend/accounts/crypto"; import { Button } from "@/components/buttons/Button"; @@ -37,12 +38,19 @@ export function LoginFormPart(props: LoginFormPartProps) { if (validatedDevice.length === 0) throw new Error(t("auth.login.deviceLengthError") ?? undefined); - const account = await login({ - mnemonic: inputMnemonic, - userData: { - device: validatedDevice, - }, - }); + let account: AsyncReturnType; + try { + account = await login({ + mnemonic: inputMnemonic, + userData: { + device: validatedDevice, + }, + }); + } catch (err) { + if ((err as any).status === 401) + throw new Error(t("auth.login.validationError") ?? undefined); + throw err; + } await importData(account, progressItems, bookmarkItems);