mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-27 02:04:09 +00:00
translations for human friendly auth errors
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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": {
|
||||
|
||||
27
src/utils/authErrorTranslation.ts
Normal file
27
src/utils/authErrorTranslation.ts
Normal 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')
|
||||
}
|
||||
Reference in New Issue
Block a user