mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-21 05:10:41 +00:00
feat: add registration invite code handling and improve error translations
- Updated AuthViews component to conditionally show invite code field based on registrationInviteRequired prop. - Enhanced error handling in auth API functions to use translateServerError for better user feedback. - Added new translations for various server error messages in English, Spanish, Russian, Chinese (Simplified and Traditional). - Modified demo initial bootstrap state to include registrationInviteRequired flag. - Updated types to include registrationInviteRequired in WebBootstrapResponse.
This commit is contained in:
@@ -93,6 +93,41 @@ export function t(key: string, params?: I18nParams): string {
|
||||
return template.replace(/\{(\w+)\}/g, (_, name: string) => String(params[name] ?? ''));
|
||||
}
|
||||
|
||||
export function translateServerError(message: string | null | undefined, fallback: string): string {
|
||||
const normalized = String(message || '').trim();
|
||||
if (!normalized) return fallback;
|
||||
|
||||
const rateLimitMatch = normalized.match(/^Rate limit exceeded\. Try again in (\d+) seconds\.$/i);
|
||||
if (rateLimitMatch) {
|
||||
return t('txt_rate_limit_try_again_seconds', { seconds: rateLimitMatch[1] });
|
||||
}
|
||||
|
||||
const key = {
|
||||
'Account is disabled': 'txt_server_error_account_disabled',
|
||||
'Client IP is required': 'txt_server_error_client_ip_required',
|
||||
'ClientId or clientSecret is incorrect. Try again': 'txt_server_error_client_credentials_incorrect',
|
||||
'Email already registered': 'txt_server_error_email_already_registered',
|
||||
'Email and password are required': 'txt_server_error_email_password_required',
|
||||
'Email is required': 'txt_server_error_email_required',
|
||||
'Invite code is invalid or expired': 'txt_server_error_invite_invalid_or_expired',
|
||||
'Invite code is required': 'txt_server_error_invite_required',
|
||||
'Invalid refresh token': 'txt_server_error_invalid_refresh_token',
|
||||
'Invalid request payload': 'txt_server_error_invalid_request_payload',
|
||||
'JWT_SECRET is not set': 'txt_server_error_jwt_secret_missing',
|
||||
'JWT_SECRET is using the default/sample value. Please change it.': 'txt_server_error_jwt_secret_default',
|
||||
'JWT_SECRET must be at least 32 characters': 'txt_server_error_jwt_secret_too_short',
|
||||
'Parameter error': 'txt_server_error_parameter_error',
|
||||
'Refresh token is required': 'txt_server_error_refresh_token_required',
|
||||
'Registration is temporarily unavailable, retry once': 'txt_server_error_registration_retry',
|
||||
'TOTP token is required': 'txt_server_error_totp_token_required',
|
||||
'Two factor required.': 'txt_server_error_two_factor_required',
|
||||
'Two-step token is invalid. Try again.': 'txt_server_error_two_factor_invalid',
|
||||
'Username or password is incorrect. Try again': 'txt_server_error_username_password_incorrect',
|
||||
}[normalized];
|
||||
|
||||
return key ? t(key) : normalized;
|
||||
}
|
||||
|
||||
export function getLocale(): Locale {
|
||||
return locale;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user