| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import { ApiClientError } from "@/lib/frontend/apiClient";
- import { LOGIN_REASONS } from "@/lib/frontend/authRedirect";
- /**
- * Auth UI messages (RHL-020).
- *
- * Why this file exists:
- * - Keep user-facing auth messages consistent and centralized.
- * - Avoid string duplication across multiple UI components.
- * - Make mappings easy to test (pure functions, no UI dependencies).
- */
- /**
- * Return a user-facing login-page alert message for a known reason.
- *
- * @param {string|null} reason
- * @returns {{ title: string, description: string } | null}
- */
- export function getLoginReasonAlert(reason) {
- if (reason === LOGIN_REASONS.EXPIRED) {
- return {
- title: "Sitzung abgelaufen",
- description:
- "Ihre Sitzung ist abgelaufen. Bitte melden Sie sich erneut an.",
- };
- }
- if (reason === LOGIN_REASONS.LOGGED_OUT) {
- return {
- title: "Abgemeldet",
- description: "Sie wurden erfolgreich abgemeldet.",
- };
- }
- return null;
- }
- /**
- * Map an error to a safe, user-friendly login error message.
- *
- * Principles:
- * - Do not leak internal server details to the UI.
- * - Use stable error codes (ApiClientError.code) for UX decisions.
- *
- * @param {unknown} err
- * @returns {string}
- */
- export function getLoginErrorMessage(err) {
- if (err instanceof ApiClientError) {
- if (err.code === "AUTH_INVALID_CREDENTIALS") {
- return "Benutzername oder Passwort ist falsch.";
- }
- if (err.code === "CLIENT_NETWORK_ERROR") {
- return "Netzwerkfehler. Bitte prüfen Sie Ihre Verbindung und versuchen Sie es erneut.";
- }
- return "Anmeldung fehlgeschlagen. Bitte erneut versuchen.";
- }
- return "Anmeldung fehlgeschlagen. Bitte erneut versuchen.";
- }
|