From b56e94fc7c1d8f64eccfd130939e374cb15de7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20P=C3=A9rez?= Date: Thu, 3 Oct 2024 13:28:53 +0200 Subject: [PATCH 1/3] Update wrong credential text --- src/app/auth/components/LogIn/LogIn.tsx | 6 +++++- src/app/i18n/locales/de.json | 3 ++- src/app/i18n/locales/en.json | 3 ++- src/app/i18n/locales/es.json | 3 ++- src/app/i18n/locales/fr.json | 3 ++- src/app/i18n/locales/it.json | 3 ++- src/app/i18n/locales/ru.json | 3 ++- src/app/i18n/locales/tw.json | 3 ++- src/app/i18n/locales/zh.json | 3 ++- 9 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/app/auth/components/LogIn/LogIn.tsx b/src/app/auth/components/LogIn/LogIn.tsx index fc73026a5..c0ff18cdf 100644 --- a/src/app/auth/components/LogIn/LogIn.tsx +++ b/src/app/auth/components/LogIn/LogIn.tsx @@ -172,7 +172,11 @@ export default function LogIn(): JSX.Element { navigationService.history.push(`/activate/${email}`); } - setLoginError([castedError.message]); + setLoginError([ + castedError.message.includes('Wrong login credentials') + ? translate('auth.login.wrongLogin') + : castedError.message, + ]); setShowErrors(true); if ((err as AppError)?.status === 403) { await sendUnblockAccountEmail(email); diff --git a/src/app/i18n/locales/de.json b/src/app/i18n/locales/de.json index c0bd40fc0..754873896 100644 --- a/src/app/i18n/locales/de.json +++ b/src/app/i18n/locales/de.json @@ -60,7 +60,8 @@ "dontHaveAccount": "Sie haben kein Konto?", "createAccount": "Konto erstellen", "2FA": "Zwei-Faktor-Code", - "twoFactorAuthenticationCode": "Zwei-Faktor-Authentifizierungscode" + "twoFactorAuthenticationCode": "Zwei-Faktor-Authentifizierungscode", + "wrongLogin": "Ungültiger Benutzername oder Passwort" }, "signup": { "title": "Konto erstellen", diff --git a/src/app/i18n/locales/en.json b/src/app/i18n/locales/en.json index 2997d0e41..275ae4e12 100644 --- a/src/app/i18n/locales/en.json +++ b/src/app/i18n/locales/en.json @@ -81,7 +81,8 @@ "dontHaveAccount": "Don't have an account?", "createAccount": "Create account", "2FA": "Two factor code", - "twoFactorAuthenticationCode": "Two factor authentication code" + "twoFactorAuthenticationCode": "Two factor authentication code", + "wrongLogin": "Invalid username or password" }, "signup": { "title": "Create account", diff --git a/src/app/i18n/locales/es.json b/src/app/i18n/locales/es.json index f82263454..20fd10777 100644 --- a/src/app/i18n/locales/es.json +++ b/src/app/i18n/locales/es.json @@ -60,7 +60,8 @@ "dontHaveAccount": "¿No tienes cuenta?", "createAccount": "Crear cuenta", "2FA": "Código de dos factores", - "twoFactorAuthenticationCode": "Código de autenticación de dos factores" + "twoFactorAuthenticationCode": "Código de autenticación de dos factores", + "wrongLogin": "Nombre de usuario o contraseña no válidos" }, "signup": { "title": "Crear cuenta", diff --git a/src/app/i18n/locales/fr.json b/src/app/i18n/locales/fr.json index 8ff1e9445..7cbda4000 100644 --- a/src/app/i18n/locales/fr.json +++ b/src/app/i18n/locales/fr.json @@ -60,7 +60,8 @@ "dontHaveAccount": "Vous n'avez pas de compte ?", "createAccount": "Créer un compte", "2FA": "Code à deux facteurs", - "twoFactorAuthenticationCode": "Code d'authentification à deux facteurs" + "twoFactorAuthenticationCode": "Code d'authentification à deux facteurs", + "wrongLogin": "Nom d'utilisateur ou mot de passe invalide" }, "signup": { "title": "Créer un compte", diff --git a/src/app/i18n/locales/it.json b/src/app/i18n/locales/it.json index f810d5282..4dbdd156a 100644 --- a/src/app/i18n/locales/it.json +++ b/src/app/i18n/locales/it.json @@ -81,7 +81,8 @@ "dontHaveAccount": "Non hai un account?", "createAccount": "Creare un account", "2FA": "Codice a due fattori", - "twoFactorAuthenticationCode": "Codice di autenticazione a due fattori" + "twoFactorAuthenticationCode": "Codice di autenticazione a due fattori", + "wrongLogin": "Nome utente o password non validi" }, "signup": { "title": "Creare un account", diff --git a/src/app/i18n/locales/ru.json b/src/app/i18n/locales/ru.json index fee8eec2e..d99b28071 100644 --- a/src/app/i18n/locales/ru.json +++ b/src/app/i18n/locales/ru.json @@ -60,7 +60,8 @@ "dontHaveAccount": "У вас нет учетной записи?", "createAccount": "Создать учетную запись", "2FA": "Двухфакторный код", - "twoFactorAuthenticationCode": "Код двухфакторной аутентификации" + "twoFactorAuthenticationCode": "Код двухфакторной аутентификации", + "wrongLogin": "Неверное имя пользователя или пароль" }, "signup": { "title": "Создать учетную запись", diff --git a/src/app/i18n/locales/tw.json b/src/app/i18n/locales/tw.json index 1e6f34b05..29c135f89 100644 --- a/src/app/i18n/locales/tw.json +++ b/src/app/i18n/locales/tw.json @@ -81,7 +81,8 @@ "dontHaveAccount": "沒有帳戶?", "createAccount": "創建帳戶", "2FA": "雙重身份驗證代碼", - "twoFactorAuthenticationCode": "雙重身份驗證代碼" + "twoFactorAuthenticationCode": "雙重身份驗證代碼", + "wrongLogin": "使用者名稱或密碼無效" }, "signup": { "title": "創建帳戶", diff --git a/src/app/i18n/locales/zh.json b/src/app/i18n/locales/zh.json index 1e4e1e797..2f1d4c697 100644 --- a/src/app/i18n/locales/zh.json +++ b/src/app/i18n/locales/zh.json @@ -81,7 +81,8 @@ "dontHaveAccount": "没有账户?", "createAccount": "创建账户", "2FA": "双因素代码", - "twoFactorAuthenticationCode": "双因素验证码" + "twoFactorAuthenticationCode": "双因素验证码", + "wrongLogin": "用户名或密码无效" }, "signup": { "title": "创建账户", From 37ede4b3ebd3789fe60fbe377807aef8ed6d4aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20P=C3=A9rez?= Date: Thu, 3 Oct 2024 16:37:02 +0200 Subject: [PATCH 2/3] Use status error --- src/app/auth/components/LogIn/LogIn.tsx | 6 +----- src/app/auth/services/auth.service.ts | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/app/auth/components/LogIn/LogIn.tsx b/src/app/auth/components/LogIn/LogIn.tsx index c0ff18cdf..c52907dcd 100644 --- a/src/app/auth/components/LogIn/LogIn.tsx +++ b/src/app/auth/components/LogIn/LogIn.tsx @@ -172,11 +172,7 @@ export default function LogIn(): JSX.Element { navigationService.history.push(`/activate/${email}`); } - setLoginError([ - castedError.message.includes('Wrong login credentials') - ? translate('auth.login.wrongLogin') - : castedError.message, - ]); + setLoginError([(err as AppError)?.status === 401 ? translate('auth.login.wrongLogin') : castedError.message]); setShowErrors(true); if ((err as AppError)?.status === 403) { await sendUnblockAccountEmail(email); diff --git a/src/app/auth/services/auth.service.ts b/src/app/auth/services/auth.service.ts index 697fa0c97..28b727592 100644 --- a/src/app/auth/services/auth.service.ts +++ b/src/app/auth/services/auth.service.ts @@ -33,7 +33,7 @@ import { generateMnemonic, validateMnemonic } from 'bip39'; import { SdkFactory } from '../../core/factory/sdk'; import httpService from '../../core/services/http.service'; import navigationService from 'app/core/services/navigation.service'; -import { AppView } from 'app/core/types'; +import AppError, { AppView } from 'app/core/types'; export async function logOut(loginParams?: Record): Promise { analyticsService.trackSignOut(); @@ -55,7 +55,7 @@ export const is2FANeeded = async (email: string): Promise => { const authClient = SdkFactory.getInstance().createAuthClient(); const securityDetails = await authClient.securityDetails(email).catch((error) => { analyticsService.signInAttempted(email, error.message); - throw new Error(error.message ?? 'Login error'); + throw new AppError(error.message ?? 'Login error', error.status ?? 500); }); return securityDetails.tfaEnabled; From b7b74a5fba707b964c4b782cb0261247d2034669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20P=C3=A9rez?= Date: Fri, 4 Oct 2024 15:58:41 +0200 Subject: [PATCH 3/3] refactor status ocde access --- src/app/auth/components/LogIn/LogIn.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/app/auth/components/LogIn/LogIn.tsx b/src/app/auth/components/LogIn/LogIn.tsx index c52907dcd..d75ff9056 100644 --- a/src/app/auth/components/LogIn/LogIn.tsx +++ b/src/app/auth/components/LogIn/LogIn.tsx @@ -32,6 +32,8 @@ import PasswordInput from '../PasswordInput/PasswordInput'; import TextInput from '../TextInput/TextInput'; import { workspaceThunks } from 'app/store/slices/workspaces/workspacesStore'; +const UNAUTHORIZED_STATUS_CODE = 401; + const showNotification = ({ text, isError }: { text: string; isError: boolean }) => { notificationsService.show({ text, @@ -96,6 +98,14 @@ export default function LogIn(): JSX.Element { [], ); + const getLoginErrorMessage = (err: unknown): string => { + const appError = err as AppError; + if (appError?.status === UNAUTHORIZED_STATUS_CODE) { + return translate('auth.login.wrongLogin'); + } + return appError?.message || 'An unexpected error occurred'; + }; + const { register, formState: { errors, isValid }, @@ -172,7 +182,7 @@ export default function LogIn(): JSX.Element { navigationService.history.push(`/activate/${email}`); } - setLoginError([(err as AppError)?.status === 401 ? translate('auth.login.wrongLogin') : castedError.message]); + setLoginError([getLoginErrorMessage(err)]); setShowErrors(true); if ((err as AppError)?.status === 403) { await sendUnblockAccountEmail(email);