From 4899c9d25bce2db9b55f8715a5a7d56cc9372be8 Mon Sep 17 00:00:00 2001 From: Jennifer Weber Date: Fri, 29 Aug 2025 21:43:04 -0700 Subject: [PATCH] translations for human friendly auth errors --- .../dialog/content/SignInContent.vue | 9 +++---- src/locales/en/main.json | 14 ++++++++++ src/utils/authErrorTranslation.ts | 27 +++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 src/utils/authErrorTranslation.ts diff --git a/src/components/dialog/content/SignInContent.vue b/src/components/dialog/content/SignInContent.vue index b0067891a0..de058ae057 100644 --- a/src/components/dialog/content/SignInContent.vue +++ b/src/components/dialog/content/SignInContent.vue @@ -153,6 +153,7 @@ import { useI18n } from 'vue-i18n' import { useFirebaseAuthActions } from '@/composables/auth/useFirebaseAuthActions' import { COMFY_PLATFORM_BASE_URL } from '@/config/comfyApi' import { SignInData, SignUpData } from '@/schemas/signInSchema' +import { translateAuthError } from '@/utils/authErrorTranslation' import { isInChina } from '@/utils/networkUtil' import ApiKeyForm from './signin/ApiKeyForm.vue' @@ -178,12 +179,8 @@ const toggleState = () => { // Custom error handler for inline display const inlineErrorHandler = (error: unknown) => { - // Set inline error - if (error instanceof Error) { - authError.value = error.message || t('g.unknownError') - } else { - authError.value = t('g.unknownError') - } + // Set inline error with auth error translation + authError.value = translateAuthError(error) // Also show toast (original behavior) authActions.reportError(error) } diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 50b6d8c3e6..0a41fa9fef 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -1601,6 +1601,20 @@ "passwordUpdate": { "success": "Password Updated", "successDetail": "Your password has been updated successfully" + }, + "errors": { + "auth/invalid-email": "Please enter a valid email address.", + "auth/user-disabled": "This account has been disabled. Please contact support.", + "auth/user-not-found": "No account found with this email. Would you like to create a new account?", + "auth/wrong-password": "The password you entered is incorrect. Please try again.", + "auth/email-already-in-use": "An account with this email already exists. Try signing in instead.", + "auth/weak-password": "Password is too weak. Please use a stronger password with at least 6 characters.", + "auth/too-many-requests": "Too many login attempts. Please wait a moment and try again.", + "auth/operation-not-allowed": "This sign-in method is not currently supported.", + "auth/invalid-credential": "Invalid login credentials. Please check your email and password.", + "auth/network-request-failed": "Network error. Please check your connection and try again.", + "auth/popup-closed-by-user": "Sign-in was cancelled. Please try again.", + "auth/cancelled-popup-request": "Sign-in was cancelled. Please try again." } }, "validation": { diff --git a/src/utils/authErrorTranslation.ts b/src/utils/authErrorTranslation.ts new file mode 100644 index 0000000000..ab329f7269 --- /dev/null +++ b/src/utils/authErrorTranslation.ts @@ -0,0 +1,27 @@ +import { FirebaseError } from 'firebase/app' + +import { t, te } from '@/i18n' + +/** + * Translates authentication errors to user-friendly messages. + * Handles Firebase errors with specific translations, and provides fallbacks for other error types. + * @param error - Any error object from authentication flows + * @returns User-friendly error message + */ +export function translateAuthError(error: unknown): string { + if (error instanceof FirebaseError) { + const translationKey = `auth.errors.${error.code}` + + // Check if translation exists using te() function + if (te(translationKey)) { + return t(translationKey) + } + } + + // Fallback to original error message or generic error + if (error instanceof Error && error.message) { + return error.message + } + + return t('g.unknownError') +}