import { getLocale } from "@/i18n/locale"; import { getDictionary } from "@/i18n/get-dictionary"; /** * Feste Hinweise fuer Weiterleitungen aus Server Components, die selbst * keine Cookies setzen duerfen (siehe app/api/hinweis/route.ts). * * Bewusst nur feste Codes mit festem Ziel — weder Text noch Ziel kommen aus * der URL. Sonst liesse sich ueber den Endpunkt beliebiger Text im * Wabenhain-Layout anzeigen (Phishing) oder auf fremde Seiten weiterleiten * (Open Redirect). */ export const NOTICES = { "admin-login": { to: "/konto", message: async () => "Bitte melde dich mit einem Admin-Konto an." }, "admin-2fa": { to: "/konto/zwei-faktor", message: async () => "Für Admin-Konten ist Zwei-Faktor-Authentifizierung erforderlich. Bitte richte sie jetzt ein.", }, "invoice-login": { to: "/konto", message: async () => getDictionary(await getLocale()).invoicePage.loginRequiredError, }, } as const satisfies Record Promise }>; export type NoticeCode = keyof typeof NOTICES; export function isNoticeCode(value: string | null): value is NoticeCode { return value !== null && Object.hasOwn(NOTICES, value); } export function noticeUrl(code: NoticeCode): string { return `/api/hinweis?code=${code}`; }