feat(auth): better-auth mit passwort, passkeys und app-shell
Registrierung des ersten Nutzers macht ihn zum Administrator, danach ist die Registrierung geschlossen (Einladungen folgen in Phase 2). Login per Passwort oder Passkey inklusive Conditional UI, Verwaltung der Passkeys unter "Konto" mit Umbenennen und Loeschen. Rate-Limiting liegt in der Datenbank und ueberlebt Neustarts; Session-Cookies sind httpOnly, sameSite=lax und im Produktivbetrieb secure. Die Client-IP wird hinter dem Reverse Proxy aus x-forwarded-for gelesen. Dazu die mobile-first Grundstruktur: Bottom-Navigation, Header mit Konto-Menue, Healthcheck unter /api/health und ein Dashboard mit den vier Einstiegspunkten. Bedienelemente sind auf 44px Touch-Groesse angehoben. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Money handling. Amounts live in the database as integer cents; euros only
|
||||
* exist for display and for what the user types. Every conversion goes through
|
||||
* this module.
|
||||
*/
|
||||
|
||||
const currencyFormatter = new Intl.NumberFormat('de-DE', {
|
||||
style: 'currency',
|
||||
currency: 'EUR',
|
||||
});
|
||||
|
||||
const decimalFormatter = new Intl.NumberFormat('de-DE', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
});
|
||||
|
||||
/** "12,99 €" - the canonical display form. */
|
||||
export function formatEuro(cents: number | null | undefined): string {
|
||||
if (cents === null || cents === undefined) return '–';
|
||||
return currencyFormatter.format(cents / 100);
|
||||
}
|
||||
|
||||
/** "12,99" - for prefilling a number input without the currency symbol. */
|
||||
export function centsToInput(cents: number | null | undefined): string {
|
||||
if (cents === null || cents === undefined) return '';
|
||||
return decimalFormatter.format(cents / 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses user input into cents. Accepts both German and English decimal
|
||||
* separators as well as thousands separators, because phone keyboards differ.
|
||||
* Returns null for empty input and NaN-ish garbage.
|
||||
*/
|
||||
export function parseEuroInput(value: string | null | undefined): number | null {
|
||||
if (value === null || value === undefined) return null;
|
||||
|
||||
const trimmed = value.trim().replace(/[€\s]/g, '');
|
||||
if (trimmed === '') return null;
|
||||
|
||||
// "1.234,56" -> "1234.56" ; "1,234.56" -> "1234.56" ; "12,99" -> "12.99"
|
||||
const lastComma = trimmed.lastIndexOf(',');
|
||||
const lastDot = trimmed.lastIndexOf('.');
|
||||
let normalized: string;
|
||||
|
||||
if (lastComma > lastDot) {
|
||||
normalized = trimmed.replace(/\./g, '').replace(',', '.');
|
||||
} else if (lastDot > lastComma) {
|
||||
normalized = trimmed.replace(/,/g, '');
|
||||
} else {
|
||||
normalized = trimmed;
|
||||
}
|
||||
|
||||
const parsed = Number.parseFloat(normalized);
|
||||
if (!Number.isFinite(parsed) || parsed < 0) return null;
|
||||
|
||||
return Math.round(parsed * 100);
|
||||
}
|
||||
|
||||
/** Sum of a list of optional cent amounts, ignoring the unknown ones. */
|
||||
export function sumCents(values: Array<number | null | undefined>): number {
|
||||
return values.reduce<number>((total, value) => total + (value ?? 0), 0);
|
||||
}
|
||||
Reference in New Issue
Block a user