diff --git a/bun.lockb b/bun.lockb index a3871086..ea95e702 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.json index be77a8a5..825b5170 100644 --- a/src/lib/i18n/en.json +++ b/src/lib/i18n/en.json @@ -780,5 +780,19 @@ "description": "Display debug information" } } + }, + "error": { + "incorrect_login": "Incorrect login credentials. Please try again.", + "incorrect_login_2": "Incorrect login credentials. Try again.", + "incorrect_login_3": "Incorrect, again. Try a few more times.", + "incorrect_login_4": "Those still aren't the right credentials. Keep trying.", + "incorrect_login_5": "I swear, you need to look at the keys you're pressing.", + "incorrect_login_6": "Is this a joke to you?", + "incorrect_login_7": "Either you struggle with typing or you're harassing me at this point.", + "incorrect_login_8": "I give up.", + "incorrect_login_9": "Each of these requests you make are sending data through via an incredible technology. And you're using it to make failed logins.", + "incorrect_login_10": "Think about this. The poor instance admins have to maintain their server just for you to make these useless requests.", + "incorrect_login_11": "I give up, for real this time.", + "incorrect_login_12": "..." } } diff --git a/src/lib/lemmy/error.ts b/src/lib/lemmy/error.ts new file mode 100644 index 00000000..4141ddec --- /dev/null +++ b/src/lib/lemmy/error.ts @@ -0,0 +1,16 @@ +import { t } from '$lib/translations' + +export function errorMessage(error: any, instance?: string): string { + try { + if (error?.body?.message) { + error = JSON.parse(error?.body?.message).error + } else if (error?.message) { + error = error?.message + } + if (!error) throw error + + return t.get(`error.${error}`) + } catch (e) { + return error as any + } +} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index c23b3bd4..a794e5b1 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -16,7 +16,13 @@ themeVars, } from '$lib/ui/colors.js' import { userSettings } from '$lib/settings.js' - import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte' + import { + Button, + ModalContainer, + Spinner, + toast, + ToastContainer, + } from 'mono-svelte' import { onMount } from 'svelte' import { browser } from '$app/environment' import { Forward, Icon } from 'svelte-hero-icons' diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte index 660338c3..977b0ecc 100644 --- a/src/routes/login/+page.svelte +++ b/src/routes/login/+page.svelte @@ -20,6 +20,7 @@ import { MINIMUM_VERSION } from '$lib/version.js' import { t } from '$lib/translations' import Header from '$lib/components/ui/layout/pages/Header.svelte' + import { errorMessage } from '$lib/lemmy/error' let data = { instance: DEFAULT_INSTANCE_URL, @@ -27,6 +28,7 @@ password: '', totp: '', loading: false, + attempts: 0, } async function logIn() { @@ -56,16 +58,26 @@ } } catch (error) { toast({ - content: error as any, + content: + JSON.parse((error as any)?.body?.message ?? '{}')?.error == + 'incorrect_login' + ? errorMessage( + 'incorrect_login' + + (data.attempts == 0 || data.attempts >= 12 + ? '' + : `_${data.attempts + 1}`) + ) + : errorMessage(error), type: 'error', }) + data.attempts++ } data.loading = false } - Login + {$t('account.login')}