| 6 | * `HTTP <status>`; we match on the known cases and fall back to generic. |
| 7 | */ |
| 8 | export function authErrorMessage(err: unknown, t: TFunction): string { |
| 9 | const msg = err instanceof Error ? err.message : String(err); |
| 10 | const lower = msg.toLowerCase(); |
| 11 | |
| 12 | if (lower.includes("401") || lower.includes("invalid")) { |
| 13 | return t("invalidCreds"); |
| 14 | } |
| 15 | if (lower.includes("409") || lower.includes("exist") || lower.includes("taken")) { |
| 16 | return t("emailTaken"); |
| 17 | } |
| 18 | if (lower.includes("400") || lower.includes("password") || lower.includes("8")) { |
| 19 | return t("passwordTooShort"); |
| 20 | } |
| 21 | return t("genericError"); |
| 22 | } |