translations for human friendly auth errors

This commit is contained in:
Jennifer Weber
2025-08-29 21:43:04 -07:00
parent 0bd3c1271d
commit 4899c9d25b
3 changed files with 44 additions and 6 deletions

View File

@@ -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)
}

View File

@@ -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": {

View File

@@ -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')
}