refactor(auth-ui): i18n, security fixes, type safety across auth components

- Add locale prop (de/en) to PasswordStrength, ChangePassword,
  SecurityOnboarding, AuditLog, AuthGate tier screen
- Add 13 new i18n keys to LoginTranslations for 2FA, lockout, magic link
- Fix date formatting to use locale in AuditLog
- Rewrite ForgotPasswordPage to Tailwind (matching Login/Register)
- Fix HTML injection in ForgotPasswordPage (remove @html with email)
- Guard DEV credentials behind isDevMode check in LoginPage
- Extend AuthResult type with twoFactorRedirect and retryAfter
- Remove as any casts in LoginPage
- Replace scoped CSS with Tailwind in AuthGate tier-denied screen

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-03-31 13:41:53 +02:00
parent c3bee2607b
commit 3b54d4d48e
8 changed files with 517 additions and 363 deletions

View file

@ -13,9 +13,16 @@
onRefresh: () => Promise<void>;
loading?: boolean;
primaryColor?: string;
locale?: 'de' | 'en';
}
let { events, onRefresh, loading = false, primaryColor = '#6366f1' }: Props = $props();
let {
events,
onRefresh,
loading = false,
primaryColor = '#6366f1',
locale = 'de',
}: Props = $props();
interface EventInfo {
label: string;
@ -23,41 +30,88 @@
badgeText: string;
}
const eventLabelsDE: Record<string, { label: string; badgeText: string }> = {
login_success: { label: 'Anmeldung erfolgreich', badgeText: '' },
login_failure: { label: 'Anmeldung fehlgeschlagen', badgeText: '' },
register: { label: 'Konto erstellt', badgeText: 'Neu' },
logout: { label: 'Abgemeldet', badgeText: '' },
password_changed: { label: 'Passwort geändert', badgeText: '' },
password_reset_requested: { label: 'Passwort-Reset angefordert', badgeText: '' },
password_reset_completed: { label: 'Passwort zurückgesetzt', badgeText: '' },
passkey_registered: { label: 'Passkey registriert', badgeText: '' },
passkey_login_success: { label: 'Passkey-Anmeldung', badgeText: '' },
passkey_deleted: { label: 'Passkey gelöscht', badgeText: '' },
two_factor_enabled: { label: '2FA aktiviert', badgeText: '' },
two_factor_disabled: { label: '2FA deaktiviert', badgeText: '' },
account_locked: { label: 'Konto gesperrt', badgeText: '' },
account_deleted: { label: 'Konto gelöscht', badgeText: '' },
sso_token_exchange: { label: 'SSO-Anmeldung', badgeText: '' },
};
const eventLabelsEN: Record<string, { label: string; badgeText: string }> = {
login_success: { label: 'Login successful', badgeText: '' },
login_failure: { label: 'Login failed', badgeText: '' },
register: { label: 'Account created', badgeText: 'New' },
logout: { label: 'Logged out', badgeText: '' },
password_changed: { label: 'Password changed', badgeText: '' },
password_reset_requested: { label: 'Password reset requested', badgeText: '' },
password_reset_completed: { label: 'Password reset', badgeText: '' },
passkey_registered: { label: 'Passkey registered', badgeText: '' },
passkey_login_success: { label: 'Passkey login', badgeText: '' },
passkey_deleted: { label: 'Passkey deleted', badgeText: '' },
two_factor_enabled: { label: '2FA enabled', badgeText: '' },
two_factor_disabled: { label: '2FA disabled', badgeText: '' },
account_locked: { label: 'Account locked', badgeText: '' },
account_deleted: { label: 'Account deleted', badgeText: '' },
sso_token_exchange: { label: 'SSO login', badgeText: '' },
};
const badgeClasses: Record<string, string> = {
login_success: 'badge-success',
login_failure: 'badge-danger',
register: 'badge-info',
logout: 'badge-neutral',
password_changed: 'badge-warning',
password_reset_requested: 'badge-warning',
password_reset_completed: 'badge-warning',
passkey_registered: 'badge-warning',
passkey_login_success: 'badge-success',
passkey_deleted: 'badge-danger',
two_factor_enabled: 'badge-success',
two_factor_disabled: 'badge-warning',
account_locked: 'badge-danger',
account_deleted: 'badge-danger',
sso_token_exchange: 'badge-success',
};
const auditTextsDE = {
title: 'Sicherheitsprotokoll',
subtitle: 'Letzte Aktivitäten deines Kontos',
refresh: 'Aktualisieren',
empty: 'Keine Sicherheitsereignisse vorhanden.',
today: 'Heute',
yesterday: 'Gestern',
};
const auditTextsEN = {
title: 'Security Log',
subtitle: 'Recent activity on your account',
refresh: 'Refresh',
empty: 'No security events found.',
today: 'Today',
yesterday: 'Yesterday',
};
const txt = $derived(locale === 'en' ? auditTextsEN : auditTextsDE);
function getEventInfo(eventType: string): EventInfo {
switch (eventType) {
case 'login_success':
return { label: 'Anmeldung erfolgreich', badgeClass: 'badge-success', badgeText: '' };
case 'login_failure':
return { label: 'Anmeldung fehlgeschlagen', badgeClass: 'badge-danger', badgeText: '' };
case 'register':
return { label: 'Konto erstellt', badgeClass: 'badge-info', badgeText: 'Neu' };
case 'logout':
return { label: 'Abgemeldet', badgeClass: 'badge-neutral', badgeText: '' };
case 'password_changed':
return { label: 'Passwort geändert', badgeClass: 'badge-warning', badgeText: '' };
case 'password_reset_requested':
return { label: 'Passwort-Reset angefordert', badgeClass: 'badge-warning', badgeText: '' };
case 'password_reset_completed':
return { label: 'Passwort zurückgesetzt', badgeClass: 'badge-warning', badgeText: '' };
case 'passkey_registered':
return { label: 'Passkey registriert', badgeClass: 'badge-warning', badgeText: '' };
case 'passkey_login_success':
return { label: 'Passkey-Anmeldung', badgeClass: 'badge-success', badgeText: '' };
case 'passkey_deleted':
return { label: 'Passkey gelöscht', badgeClass: 'badge-danger', badgeText: '' };
case 'two_factor_enabled':
return { label: '2FA aktiviert', badgeClass: 'badge-success', badgeText: '' };
case 'two_factor_disabled':
return { label: '2FA deaktiviert', badgeClass: 'badge-warning', badgeText: '' };
case 'account_locked':
return { label: 'Konto gesperrt', badgeClass: 'badge-danger', badgeText: '' };
case 'account_deleted':
return { label: 'Konto gelöscht', badgeClass: 'badge-danger', badgeText: '' };
case 'sso_token_exchange':
return { label: 'SSO-Anmeldung', badgeClass: 'badge-success', badgeText: '' };
default:
return { label: eventType, badgeClass: 'badge-neutral', badgeText: '' };
const labels = locale === 'en' ? eventLabelsEN : eventLabelsDE;
const info = labels[eventType];
const badgeClass = badgeClasses[eventType] || 'badge-neutral';
if (info) {
return { label: info.label, badgeClass, badgeText: info.badgeText };
}
return { label: eventType, badgeClass: 'badge-neutral', badgeText: '' };
}
function formatDate(dateStr: string): string {
@ -65,18 +119,19 @@
const now = new Date();
const diffMs = now.getTime() - date.getTime();
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
const dateLocale = locale === 'en' ? 'en-US' : 'de-DE';
const timeStr = date.toLocaleTimeString('de-DE', {
const timeStr = date.toLocaleTimeString(dateLocale, {
hour: '2-digit',
minute: '2-digit',
});
if (diffDays === 0) {
return `Heute, ${timeStr}`;
return `${txt.today}, ${timeStr}`;
} else if (diffDays === 1) {
return `Gestern, ${timeStr}`;
return `${txt.yesterday}, ${timeStr}`;
} else {
const dateFormatted = date.toLocaleDateString('de-DE', {
const dateFormatted = date.toLocaleDateString(dateLocale, {
day: '2-digit',
month: '2-digit',
year: 'numeric',
@ -124,8 +179,8 @@
</svg>
</div>
<div>
<h3 class="audit-title">Sicherheitsprotokoll</h3>
<p class="audit-subtitle">Letzte Aktivitäten deines Kontos</p>
<h3 class="audit-title">{txt.title}</h3>
<p class="audit-subtitle">{txt.subtitle}</p>
</div>
</div>
<button
@ -133,7 +188,7 @@
class="refresh-button"
onclick={onRefresh}
disabled={loading}
aria-label="Aktualisieren"
aria-label={txt.refresh}
>
<svg
class="refresh-icon"
@ -157,7 +212,7 @@
<div class="loading-spinner"></div>
</div>
{:else if events.length === 0}
<p class="empty-state">Keine Sicherheitsereignisse vorhanden.</p>
<p class="empty-state">{txt.empty}</p>
{:else}
<div class="event-list">
{#each events as event (event.id)}

View file

@ -40,6 +40,8 @@
requiredTier?: AccessTier;
/** App name shown on the access denied screen */
appName?: string;
/** Locale for tier-denied screen (default: 'de') */
locale?: 'de' | 'en';
/** Callback invoked after auth is confirmed, before children are rendered.
* Use this for loading app-specific data (projects, calendars, etc.) */
onReady?: () => void | Promise<void>;
@ -55,6 +57,7 @@
allowGuest = false,
requiredTier,
appName,
locale = 'de',
onReady,
goto: gotoFn,
children,
@ -91,8 +94,9 @@
if (requiredTier && authStore.isAuthenticated && authStore.user) {
const userTier = authStore.user.tier || 'public';
if (!hasAppAccess(userTier, requiredTier)) {
userTierLabel = ACCESS_TIER_LABELS['de'][userTier as AccessTier] || userTier;
requiredTierLabel = ACCESS_TIER_LABELS['de'][requiredTier] || requiredTier;
const labels = ACCESS_TIER_LABELS[locale] || ACCESS_TIER_LABELS['de'];
userTierLabel = labels[userTier as AccessTier] || userTier;
requiredTierLabel = labels[requiredTier] || requiredTier;
tierDenied = true;
return;
}
@ -107,28 +111,57 @@
</script>
{#if tierDenied}
<div class="tier-denied">
<div class="tier-denied-card">
<div
class="flex items-center justify-center min-h-screen p-6"
style:background-color="hsl(var(--background, 0 0% 100%))"
>
<div
class="max-w-96 w-full text-center py-10 px-8 rounded-2xl border shadow-sm"
style:border-color="hsl(var(--border, 0 0% 90%))"
style:background-color="hsl(var(--card, 0 0% 100%))"
>
{#if appName}
<h1 class="tier-denied-title">{appName}</h1>
<h1 class="text-xl font-bold mb-4" style:color="hsl(var(--foreground, 0 0% 9%))">
{appName}
</h1>
{/if}
<div class="tier-denied-icon">🔒</div>
<p class="tier-denied-message">
Diese App ist aktuell in der geschlossenen <strong>{requiredTierLabel}</strong>-Phase.
<div class="text-5xl mb-4">🔒</div>
<p
class="text-[0.9375rem] leading-relaxed mb-6"
style:color="hsl(var(--muted-foreground, 0 0% 45%))"
>
{locale === 'en'
? `This app is currently in closed `
: `Diese App ist aktuell in der geschlossenen `}<strong>{requiredTierLabel}</strong
>{locale === 'en' ? ' phase.' : '-Phase.'}
</p>
<div class="tier-denied-info">
<div class="tier-row">
<span class="tier-label">Dein Zugang:</span>
<span class="tier-value">{userTierLabel}</span>
<div
class="flex flex-col gap-2 p-4 rounded-xl mb-6"
style:background-color="hsl(var(--muted, 0 0% 96%))"
>
<div class="flex justify-between items-center text-sm">
<span style:color="hsl(var(--muted-foreground, 0 0% 45%))"
>{locale === 'en' ? 'Your access:' : 'Dein Zugang:'}</span
>
<span class="font-semibold" style:color="hsl(var(--foreground, 0 0% 9%))"
>{userTierLabel}</span
>
</div>
<div class="tier-row">
<span class="tier-label">Benötigt:</span>
<span class="tier-value tier-required">{requiredTierLabel}</span>
<div class="flex justify-between items-center text-sm">
<span style:color="hsl(var(--muted-foreground, 0 0% 45%))"
>{locale === 'en' ? 'Required:' : 'Benötigt:'}</span
>
<span class="font-semibold text-violet-500">{requiredTierLabel}</span>
</div>
</div>
<div class="tier-denied-actions">
<button class="tier-btn-primary" onclick={goHome}> Zur Übersicht </button>
</div>
<button
class="w-full py-2.5 px-4 rounded-lg border-none text-sm font-medium cursor-pointer transition-opacity hover:opacity-90"
style:background-color="hsl(var(--primary, 239 84% 67%))"
style:color="hsl(var(--primary-foreground, 0 0% 100%))"
onclick={goHome}
>
{locale === 'en' ? 'Back to overview' : 'Zur Übersicht'}
</button>
</div>
</div>
{:else if !ready}
@ -138,97 +171,3 @@
{:else}
{@render children()}
{/if}
<style>
.tier-denied {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: hsl(var(--background, 0 0% 100%));
padding: 1.5rem;
}
.tier-denied-card {
max-width: 24rem;
width: 100%;
text-align: center;
padding: 2.5rem 2rem;
border-radius: 1rem;
border: 1px solid hsl(var(--border, 0 0% 90%));
background: hsl(var(--card, 0 0% 100%));
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}
.tier-denied-title {
font-size: 1.25rem;
font-weight: 700;
color: hsl(var(--foreground, 0 0% 9%));
margin: 0 0 1rem;
}
.tier-denied-icon {
font-size: 3rem;
margin-bottom: 1rem;
}
.tier-denied-message {
font-size: 0.9375rem;
color: hsl(var(--muted-foreground, 0 0% 45%));
margin: 0 0 1.5rem;
line-height: 1.5;
}
.tier-denied-info {
display: flex;
flex-direction: column;
gap: 0.5rem;
padding: 1rem;
border-radius: 0.75rem;
background: hsl(var(--muted, 0 0% 96%));
margin-bottom: 1.5rem;
}
.tier-row {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.875rem;
}
.tier-label {
color: hsl(var(--muted-foreground, 0 0% 45%));
}
.tier-value {
font-weight: 600;
color: hsl(var(--foreground, 0 0% 9%));
}
.tier-required {
color: #8b5cf6;
}
.tier-denied-actions {
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.tier-btn-primary {
width: 100%;
padding: 0.625rem 1rem;
border-radius: 0.5rem;
border: none;
background: hsl(var(--primary, 239 84% 67%));
color: hsl(var(--primary-foreground, 0 0% 100%));
font-size: 0.875rem;
font-weight: 500;
cursor: pointer;
transition: opacity 0.15s;
}
.tier-btn-primary:hover {
opacity: 0.9;
}
</style>

View file

@ -8,9 +8,42 @@
newPassword: string
) => Promise<{ success: boolean; error?: string }>;
primaryColor?: string;
locale?: 'de' | 'en';
}
let { onChangePassword, primaryColor = '#6366f1' }: Props = $props();
let { onChangePassword, primaryColor = '#6366f1', locale = 'de' }: Props = $props();
const textsDE = {
title: 'Passwort ändern',
successMessage: 'Passwort erfolgreich geändert.',
currentPasswordLabel: 'Aktuelles Passwort',
newPasswordLabel: 'Neues Passwort',
confirmPasswordLabel: 'Neues Passwort bestätigen',
hidePassword: 'Passwort verbergen',
showPassword: 'Passwort anzeigen',
minChars: 'Mindestens 8 Zeichen',
passwordsMismatch: 'Passwörter stimmen nicht überein',
submitting: 'Wird geändert...',
submit: 'Passwort ändern',
defaultError: 'Fehler beim Ändern des Passworts',
};
const textsEN = {
title: 'Change Password',
successMessage: 'Password changed successfully.',
currentPasswordLabel: 'Current Password',
newPasswordLabel: 'New Password',
confirmPasswordLabel: 'Confirm New Password',
hidePassword: 'Hide password',
showPassword: 'Show password',
minChars: 'At least 8 characters',
passwordsMismatch: 'Passwords do not match',
submitting: 'Changing...',
submit: 'Change Password',
defaultError: 'Error changing password',
};
const txt = $derived(locale === 'en' ? textsEN : textsDE);
let currentPassword = $state('');
let newPassword = $state('');
@ -53,17 +86,17 @@
reset();
setTimeout(() => (success = false), 4000);
} else {
error = result.error || 'Fehler beim Ändern des Passworts';
error = result.error || txt.defaultError;
}
}
</script>
<div class="change-password">
<h3 class="section-title">Passwort ändern</h3>
<h3 class="section-title">{txt.title}</h3>
{#if success}
<div class="success-message" role="status">
<p>Passwort erfolgreich geändert.</p>
<p>{txt.successMessage}</p>
</div>
{/if}
@ -80,7 +113,7 @@
}}
>
<div class="input-group">
<label for="current-password" class="input-label">Aktuelles Passwort</label>
<label for="current-password" class="input-label">{txt.currentPasswordLabel}</label>
<div class="input-wrapper">
<input
id="current-password"
@ -95,7 +128,7 @@
type="button"
onclick={() => (showCurrentPassword = !showCurrentPassword)}
class="password-toggle"
aria-label={showCurrentPassword ? 'Passwort verbergen' : 'Passwort anzeigen'}
aria-label={showCurrentPassword ? txt.hidePassword : txt.showPassword}
>
{#if showCurrentPassword}
<EyeSlash size={18} />
@ -107,7 +140,7 @@
</div>
<div class="input-group">
<label for="new-password" class="input-label">Neues Passwort</label>
<label for="new-password" class="input-label">{txt.newPasswordLabel}</label>
<div class="input-wrapper">
<input
id="new-password"
@ -123,7 +156,7 @@
type="button"
onclick={() => (showNewPassword = !showNewPassword)}
class="password-toggle"
aria-label={showNewPassword ? 'Passwort verbergen' : 'Passwort anzeigen'}
aria-label={showNewPassword ? txt.hidePassword : txt.showPassword}
>
{#if showNewPassword}
<EyeSlash size={18} />
@ -133,16 +166,16 @@
</button>
</div>
{#if newPassword.length > 0 && !passwordLongEnough}
<p class="field-hint error">Mindestens 8 Zeichen</p>
<p class="field-hint error">{txt.minChars}</p>
{:else}
<p class="field-hint">Mindestens 8 Zeichen</p>
<p class="field-hint">{txt.minChars}</p>
{/if}
</div>
<PasswordStrength password={newPassword} {primaryColor} />
<PasswordStrength password={newPassword} {primaryColor} {locale} />
<div class="input-group">
<label for="confirm-password" class="input-label">Neues Passwort bestätigen</label>
<label for="confirm-password" class="input-label">{txt.confirmPasswordLabel}</label>
<div class="input-wrapper">
<input
id="confirm-password"
@ -158,7 +191,7 @@
type="button"
onclick={() => (showConfirmPassword = !showConfirmPassword)}
class="password-toggle"
aria-label={showConfirmPassword ? 'Passwort verbergen' : 'Passwort anzeigen'}
aria-label={showConfirmPassword ? txt.hidePassword : txt.showPassword}
>
{#if showConfirmPassword}
<EyeSlash size={18} />
@ -168,7 +201,7 @@
</button>
</div>
{#if confirmPassword.length > 0 && !passwordsMatch}
<p class="field-hint error">Passwörter stimmen nicht überein</p>
<p class="field-hint error">{txt.passwordsMismatch}</p>
{/if}
</div>
@ -179,7 +212,7 @@
style:background-color={primaryColor + '60'}
style:border-color={primaryColor}
>
{loading ? 'Wird geändert...' : 'Passwort ändern'}
{loading ? txt.submitting : txt.submit}
</button>
</form>
</div>

View file

@ -5,9 +5,10 @@
interface Props {
password: string;
primaryColor?: string;
locale?: 'de' | 'en';
}
let { password, primaryColor = '#6366f1' }: Props = $props();
let { password, primaryColor = '#6366f1', locale = 'de' }: Props = $props();
let score = $state(0);
let feedback = $state('');
@ -29,7 +30,9 @@
initialized = true;
}
const labels = ['Sehr schwach', 'Schwach', 'OK', 'Stark', 'Sehr stark'];
const labelsDE = ['Sehr schwach', 'Schwach', 'OK', 'Stark', 'Sehr stark'];
const labelsEN = ['Very weak', 'Weak', 'OK', 'Strong', 'Very strong'];
const labels = $derived(locale === 'en' ? labelsEN : labelsDE);
const colors = ['#ef4444', '#f97316', '#eab308', '#84cc16', '#22c55e'];
$effect(() => {

View file

@ -4,9 +4,48 @@
onSkip: () => void;
passkeyAvailable: boolean;
primaryColor?: string;
locale?: 'de' | 'en';
}
let { onSetupPasskey, onSkip, passkeyAvailable, primaryColor = '#6366f1' }: Props = $props();
let {
onSetupPasskey,
onSkip,
passkeyAvailable,
primaryColor = '#6366f1',
locale = 'de',
}: Props = $props();
const textsDE = {
passkeySetup: 'Passkey eingerichtet!',
passkeySetupDescription:
'Dein Konto ist jetzt mit einem Passkey gesichert. Du kannst dich ab sofort ohne Passwort anmelden.',
continue: 'Weiter',
secureYourAccount: 'Sichere dein Konto',
secureDescription: 'Schütze dein Konto mit zusätzlicher Sicherheit.',
setupPasskey: 'Passkey einrichten',
passkeyDescription: 'Anmelden ohne Passwort mit Touch ID, Face ID oder Windows Hello',
setupNow: 'Jetzt einrichten',
hint2fa: 'Du kannst 2FA jederzeit in den Einstellungen aktivieren.',
skip: 'Überspringen',
defaultError: 'Fehler beim Einrichten des Passkeys',
};
const textsEN = {
passkeySetup: 'Passkey set up!',
passkeySetupDescription:
'Your account is now secured with a passkey. You can sign in without a password from now on.',
continue: 'Continue',
secureYourAccount: 'Secure your account',
secureDescription: 'Protect your account with additional security.',
setupPasskey: 'Set up Passkey',
passkeyDescription: 'Sign in without a password using Touch ID, Face ID, or Windows Hello',
setupNow: 'Set up now',
hint2fa: 'You can enable 2FA at any time in Settings.',
skip: 'Skip',
defaultError: 'Error setting up passkey',
};
const txt = $derived(locale === 'en' ? textsEN : textsDE);
let loading = $state(false);
let error = $state<string | null>(null);
@ -23,7 +62,7 @@
if (result.success) {
success = true;
} else {
error = result.error || 'Fehler beim Einrichten des Passkeys';
error = result.error || txt.defaultError;
}
}
</script>
@ -45,10 +84,9 @@
<polyline points="20 6 9 17 4 12" />
</svg>
</div>
<h2 class="onboarding-title">Passkey eingerichtet!</h2>
<h2 class="onboarding-title">{txt.passkeySetup}</h2>
<p class="onboarding-description">
Dein Konto ist jetzt mit einem Passkey gesichert. Du kannst dich ab sofort ohne Passwort
anmelden.
{txt.passkeySetupDescription}
</p>
<button
type="button"
@ -57,7 +95,7 @@
style:border-color={primaryColor}
onclick={onSkip}
>
Weiter
{txt.continue}
</button>
</div>
{:else}
@ -77,8 +115,8 @@
<path d="M7 11V7a5 5 0 0 1 10 0v4" />
</svg>
</div>
<h2 class="onboarding-title">Sichere dein Konto</h2>
<p class="onboarding-description">Schütze dein Konto mit zusätzlicher Sicherheit.</p>
<h2 class="onboarding-title">{txt.secureYourAccount}</h2>
<p class="onboarding-description">{txt.secureDescription}</p>
{#if error}
<div class="error-message" role="alert">
@ -104,9 +142,9 @@
</svg>
</div>
<div class="option-content">
<h3 class="option-title">Passkey einrichten</h3>
<h3 class="option-title">{txt.setupPasskey}</h3>
<p class="option-description">
Anmelden ohne Passwort mit Touch ID, Face ID oder Windows Hello
{txt.passkeyDescription}
</p>
</div>
<button
@ -117,14 +155,14 @@
disabled={loading}
onclick={handleSetupPasskey}
>
{loading ? '...' : 'Jetzt einrichten'}
{loading ? '...' : txt.setupNow}
</button>
</div>
{/if}
<p class="hint-text">Du kannst 2FA jederzeit in den Einstellungen aktivieren.</p>
<p class="hint-text">{txt.hint2fa}</p>
<button type="button" class="skip-button" onclick={onSkip}> Überspringen </button>
<button type="button" class="skip-button" onclick={onSkip}> {txt.skip} </button>
</div>
{/if}
</div>

View file

@ -121,10 +121,6 @@
}
}
function getPageBackground() {
return isDark ? darkBackground : lightBackground;
}
async function handleForgotPassword() {
loading = true;
error = null;
@ -151,23 +147,23 @@
<svelte:head>
<title>Forgot Password - {appName}</title>
<meta name="theme-color" content={darkBackground} media="(prefers-color-scheme: dark)" />
<meta name="theme-color" content={lightBackground} media="(prefers-color-scheme: light)" />
</svelte:head>
<div
class="flex min-h-screen flex-col justify-between"
style="background-color: {getPageBackground()}; max-width: 100vw; overflow-x: hidden;"
class="flex flex-col min-h-screen min-h-dvh w-full max-w-[100vw] overflow-x-hidden m-0 p-0"
style:background-color={isDark ? darkBackground || '#121212' : lightBackground || '#f5f5f5'}
style:--primary-color={primaryColor}
>
<!-- Theme Toggle - Top Left -->
<button
type="button"
onclick={toggleTheme}
style="position: absolute; top: 1rem; left: 1rem; z-index: 50; display: flex; align-items: center; justify-content: center; width: 2.5rem; height: 2.5rem; border-radius: 0.5rem; border: 1px solid {isDark
? 'rgba(255, 255, 255, 0.2)'
: 'rgba(0, 0, 0, 0.2)'}; background: {isDark
? 'rgba(255, 255, 255, 0.1)'
: 'rgba(0, 0, 0, 0.05)'}; color: {isDark
? 'rgba(255, 255, 255, 0.7)'
: 'rgba(0, 0, 0, 0.7)'}; cursor: pointer; transition: all 0.2s ease;"
class="absolute top-4 left-4 z-50 flex items-center justify-center w-10 h-10 rounded-lg border cursor-pointer transition-all"
style:border-color={isDark ? 'rgba(255,255,255,0.2)' : 'rgba(0,0,0,0.2)'}
style:background-color={isDark ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.05)'}
style:color={isDark ? 'rgba(255,255,255,0.7)' : 'rgba(0,0,0,0.7)'}
aria-label={isDark ? 'Switch to light mode' : 'Switch to dark mode'}
>
{#if isDark}
@ -178,174 +174,231 @@
</button>
{#if headerControls}
<div
style="position: absolute; top: 1rem; right: 1rem; z-index: 50; opacity: 0.6; display: flex; gap: 0.75rem;"
>
<div class="absolute top-4 right-4 z-50 opacity-60 flex gap-3">
{@render headerControls()}
</div>
{/if}
<!-- Top Section - Logo -->
<div class="flex flex-col items-center justify-center pt-16 pb-8">
<div
class="flex items-center justify-center rounded-full transition-all mb-4"
style="width: 120px; height: 120px; border: 3px solid {primaryColor}; background-color: {isDark
? '#000'
: '#fff'}; box-shadow: {isDark
? '0 6px 12px rgba(0, 0, 0, 0.4)'
: '0 6px 12px rgba(0, 0, 0, 0.15)'};"
>
<Logo size={55} color={primaryColor} />
</div>
<h1 class="text-2xl font-semibold" style="color: {isDark ? '#ffffff' : '#000000'};">
{appName}
</h1>
</div>
<!-- Middle Section - Form -->
<div class="flex-1 flex items-start justify-center px-5 pt-8 pb-8">
<div
class="w-full max-w-md rounded-xl p-6"
style="background-color: {isDark
? 'rgba(255, 255, 255, 0.08)'
: 'rgba(255, 255, 255, 0.7)'}; backdrop-filter: blur(10px); border: 1px solid {isDark
? 'rgba(255, 255, 255, 0.1)'
: 'rgba(0, 0, 0, 0.1)'};"
>
<!-- Title -->
<h2
class="mb-6 text-center text-xl font-semibold"
style="color: {isDark ? 'rgba(255, 255, 255, 0.9)' : 'rgba(0, 0, 0, 0.9)'};"
<main class="flex-1 flex flex-col">
<!-- Logo Section -->
<div class="flex flex-col items-center pt-12 max-[480px]:pt-8 px-4 pb-6 anim-fade-in-scale">
<div
class="w-[100px] h-[100px] max-[480px]:w-[80px] max-[480px]:h-[80px] rounded-full border-[3px] flex items-center justify-center mb-3 shadow-lg"
style:border-color={primaryColor}
style:background-color={isDark ? '#000' : '#fff'}
>
{mode === 'form' ? t.titleForm : t.titleSuccess}
</h2>
<Logo size={55} color={primaryColor} />
</div>
<h1 class="text-2xl font-semibold" style:color={isDark ? '#fff' : '#000'}>{appName}</h1>
</div>
<!-- Error Messages -->
{#if error}
<div class="mb-4 rounded-xl bg-red-500/20 border border-red-500/30 p-3">
<p class="text-sm text-red-500">{error}</p>
</div>
{/if}
<!-- Form Mode -->
{#if mode === 'form'}
<form
onsubmit={(e) => {
e.preventDefault();
handleForgotPassword();
}}
class="pb-4"
<!-- Form Section -->
<div class="flex-1 flex justify-center px-4 pt-4 pb-8">
<div
class="w-full max-w-[400px] rounded-2xl p-6 max-[480px]:p-5 border backdrop-blur-[10px] anim-fade-in-up"
style:background-color={isDark ? 'rgba(255,255,255,0.08)' : 'rgba(255,255,255,0.7)'}
style:border-color={isDark ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.1)'}
>
<!-- Title -->
<h2
class="text-xl font-semibold text-center mb-6"
style:color={isDark ? 'rgba(255,255,255,0.9)' : 'rgba(0,0,0,0.9)'}
>
<p
class="mb-4 text-sm"
style="color: {isDark ? 'rgba(255, 255, 255, 0.7)' : 'rgba(0, 0, 0, 0.7)'};"
>
{t.description}
</p>
{mode === 'form' ? t.titleForm : t.titleSuccess}
</h2>
<div class="mb-4">
<input
type="email"
bind:value={email}
placeholder={t.emailPlaceholder}
required
class="h-14 w-full rounded-xl border px-4 text-lg transition-colors focus:outline-none focus:ring-2"
style="background-color: {isDark
? 'rgba(0, 0, 0, 0.2)'
: 'rgba(255, 255, 255, 0.8)'}; border-color: {isDark
? 'rgba(255, 255, 255, 0.2)'
: 'rgba(0, 0, 0, 0.1)'}; color: {isDark
? '#ffffff'
: '#000000'}; --tw-ring-color: {primaryColor};"
/>
<!-- Error Messages -->
{#if error}
<div
class="flex items-start gap-2 p-3 mb-4 rounded-xl text-sm bg-red-500/15 border border-red-500/30 text-red-500"
role="alert"
>
<p>{error}</p>
</div>
{/if}
<button
type="submit"
disabled={loading}
class="flex h-14 w-full items-center justify-center gap-2 rounded-xl font-medium transition-all hover:opacity-80 disabled:opacity-50 border-2"
style="background-color: {primaryColor}60; border-color: {primaryColor}; color: {isDark
? '#ffffff'
: '#000000'};"
<!-- Form Mode -->
{#if mode === 'form'}
<form
onsubmit={(e) => {
e.preventDefault();
handleForgotPassword();
}}
>
<Key size={20} class="inline-block" />
{loading ? t.sending : t.sendResetLinkButton}
</button>
</form>
<!-- Back Button -->
<div class="mt-4">
<button
onclick={() => goto(loginPath)}
class="flex h-10 w-full items-center justify-center gap-2 rounded-xl font-medium transition-all hover:opacity-80"
style="color: {isDark ? '#ffffff' : '#000000'};"
>
<ArrowLeft size={20} class="inline-block" />
{t.backToLogin}
</button>
</div>
<!-- Success Mode -->
{:else}
<div class="pb-4">
<div class="flex flex-col items-center mb-6">
<div
class="w-20 h-20 rounded-full flex items-center justify-center mb-6"
style="background-color: {primaryColor}30; color: {primaryColor};"
<p
class="mb-4 text-sm"
style:color={isDark ? 'rgba(255,255,255,0.7)' : 'rgba(0,0,0,0.7)'}
>
<EnvelopeOpen size={40} />
{t.description}
</p>
<div class="mb-4">
<input
type="email"
bind:value={email}
placeholder={t.emailPlaceholder}
required
class="w-full h-14 px-4 border rounded-xl text-base transition-colors focus:outline-none focus:ring-2"
style:--ring-color={primaryColor}
style:background-color={isDark ? 'rgba(0,0,0,0.2)' : 'rgba(255,255,255,0.8)'}
style:border-color={isDark ? 'rgba(255,255,255,0.2)' : 'rgba(0,0,0,0.1)'}
style:color={isDark ? '#fff' : '#000'}
style:--tw-ring-color="var(--ring-color)"
/>
</div>
<p
class="text-sm text-center px-2"
style="color: {isDark ? 'rgba(255, 255, 255, 0.7)' : 'rgba(0, 0, 0, 0.7)'};"
>
{@html getSuccessMessage(resetEmail).replace(
resetEmail,
`<strong>${resetEmail}</strong>`
)}
</p>
</div>
<div class="flex flex-col gap-3">
<button
onclick={() => goto(loginPath)}
class="flex h-14 items-center justify-center gap-2 rounded-xl font-medium transition-all hover:opacity-80 border-2"
style="background-color: {primaryColor}60; border-color: {primaryColor}; color: {isDark
? '#ffffff'
: '#000000'};"
type="submit"
disabled={loading}
class="w-full h-14 border-2 rounded-xl font-medium flex items-center justify-center gap-2 cursor-pointer transition-opacity hover:opacity-85 disabled:opacity-50 disabled:cursor-not-allowed"
style:background-color={primaryColor + '60'}
style:border-color={primaryColor}
style:color={isDark ? '#fff' : '#000'}
>
<SignIn size={20} class="inline-block" />
<Key size={20} />
{loading ? t.sending : t.sendResetLinkButton}
</button>
</form>
<!-- Back Button -->
<div class="mt-4">
<button
type="button"
onclick={() => goto(loginPath)}
class="w-full bg-transparent border-none cursor-pointer font-medium text-sm p-3 text-center flex items-center justify-center gap-2 transition-opacity hover:opacity-70"
style:color={isDark ? '#fff' : '#000'}
>
<ArrowLeft size={20} />
{t.backToLogin}
</button>
<button
onclick={() => {
mode = 'form';
error = null;
}}
class="flex h-10 items-center justify-center gap-2 rounded-xl font-medium transition-all hover:opacity-80 border"
style="background-color: {isDark
? 'rgba(255, 255, 255, 0.1)'
: 'rgba(255, 255, 255, 0.8)'}; border-color: {isDark
? 'rgba(255, 255, 255, 0.2)'
: 'rgba(0, 0, 0, 0.1)'}; color: {isDark ? '#ffffff' : '#000000'};"
>
{t.resendEmail}
</button>
</div>
</div>
{/if}
</div>
</div>
<!-- App Slider -->
{#if appSlider}
<div class="w-full px-4 pb-8">
{@render appSlider()}
<!-- Success Mode -->
{:else}
<div class="pb-4">
<div class="flex flex-col items-center mb-6">
<div
class="w-20 h-20 rounded-full flex items-center justify-center mb-6"
style:background-color={primaryColor + '30'}
style:color={primaryColor}
>
<EnvelopeOpen size={40} />
</div>
<p
class="text-sm text-center px-2"
style:color={isDark ? 'rgba(255,255,255,0.7)' : 'rgba(0,0,0,0.7)'}
>
{getSuccessMessage(resetEmail)}
</p>
</div>
<div class="flex flex-col gap-3">
<button
type="button"
onclick={() => goto(loginPath)}
class="w-full h-14 border-2 rounded-xl font-medium flex items-center justify-center gap-2 cursor-pointer transition-opacity hover:opacity-85 disabled:opacity-50 disabled:cursor-not-allowed"
style:background-color={primaryColor + '60'}
style:border-color={primaryColor}
style:color={isDark ? '#fff' : '#000'}
>
<SignIn size={20} />
{t.backToLogin}
</button>
<button
type="button"
onclick={() => {
mode = 'form';
error = null;
}}
class="w-full h-10 border rounded-xl font-medium flex items-center justify-center gap-2 cursor-pointer transition-opacity hover:opacity-70"
style:background-color={isDark ? 'rgba(255,255,255,0.1)' : 'rgba(255,255,255,0.8)'}
style:border-color={isDark ? 'rgba(255,255,255,0.2)' : 'rgba(0,0,0,0.1)'}
style:color={isDark ? '#fff' : '#000'}
>
{t.resendEmail}
</button>
</div>
</div>
{/if}
</div>
</div>
{:else}
<!-- Bottom padding -->
<div class="pb-8"></div>
</main>
{#if appSlider}
<footer class="w-full pb-4 anim-fade-in">
{@render appSlider()}
</footer>
{/if}
</div>
<style>
:global(html, body) {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
/* Entrance Animations */
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fadeInScale {
from {
opacity: 0;
transform: scale(0.9);
}
to {
opacity: 1;
transform: scale(1);
}
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.anim-fade-in-scale {
animation: fadeInScale 0.5s ease-out both;
}
.anim-fade-in-up {
animation: fadeInUp 0.5s ease-out 0.15s both;
}
.anim-fade-in {
animation: fadeIn 0.5s ease-out 0.3s both;
}
/* Focus ring color via CSS variable */
input:focus {
--tw-ring-color: var(--ring-color, currentColor);
}
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
.anim-fade-in-scale,
.anim-fade-in-up,
.anim-fade-in {
animation: none;
}
* {
transition-duration: 0.01ms !important;
}
}
</style>

View file

@ -29,6 +29,23 @@
resendVerification?: string;
resendingVerification?: string;
verificationEmailSent?: string;
twoFactorTitle?: string;
twoFactorSubtitle?: string;
twoFactorBackupSubtitle?: string;
twoFactorBackupPlaceholder?: string;
twoFactorTrustDevice?: string;
twoFactorVerifying?: string;
twoFactorConfirm?: string;
twoFactorUseAuthenticator?: string;
twoFactorUseBackupCode?: string;
twoFactorBackToLogin?: string;
accountLocked?: string;
tooManyAttempts?: string;
retryIn?: string;
resetPassword?: string;
magicLinkSent?: string;
magicLinkSending?: string;
magicLinkButton?: string;
}
const defaultTranslations: LoginTranslations = {
@ -57,6 +74,23 @@
resendVerification: 'Resend verification email',
resendingVerification: 'Sending...',
verificationEmailSent: 'Verification email sent! Please check your inbox.',
twoFactorTitle: 'Zwei-Faktor-Authentifizierung',
twoFactorSubtitle: 'Gib den Code aus deiner Authenticator-App ein',
twoFactorBackupSubtitle: 'Gib einen Backup-Code ein',
twoFactorBackupPlaceholder: 'Backup-Code',
twoFactorTrustDevice: 'Diesem Gerät 30 Tage vertrauen',
twoFactorVerifying: 'Prüfe...',
twoFactorConfirm: 'Bestätigen',
twoFactorUseAuthenticator: 'Authenticator-App verwenden',
twoFactorUseBackupCode: 'Backup-Code verwenden',
twoFactorBackToLogin: 'Zurück zum Login',
accountLocked: 'Konto vorübergehend gesperrt',
tooManyAttempts: 'Zu viele fehlgeschlagene Anmeldeversuche.',
retryIn: 'Erneut versuchen in',
resetPassword: 'Passwort zurücksetzen',
magicLinkSent: 'Login-Link an {email} gesendet!',
magicLinkSending: 'Wird gesendet...',
magicLinkButton: 'Login-Link per E-Mail senden',
};
interface Props {
@ -462,15 +496,13 @@
class="text-xl font-semibold"
style:color={isDark ? 'rgba(255,255,255,0.9)' : 'rgba(0,0,0,0.9)'}
>
Zwei-Faktor-Authentifizierung
{t.twoFactorTitle}
</h2>
<p
class="text-sm mt-2"
style:color={isDark ? 'rgba(255,255,255,0.6)' : 'rgba(0,0,0,0.6)'}
>
{useBackupCode
? 'Gib einen Backup-Code ein'
: 'Gib den Code aus deiner Authenticator-App ein'}
{useBackupCode ? t.twoFactorBackupSubtitle : t.twoFactorSubtitle}
</p>
</div>
@ -494,7 +526,7 @@
<input
type="text"
bind:value={twoFactorCode}
placeholder={useBackupCode ? 'Backup-Code' : '000000'}
placeholder={useBackupCode ? t.twoFactorBackupPlaceholder : '000000'}
required
autocomplete="one-time-code"
inputmode={useBackupCode ? 'text' : 'numeric'}
@ -522,7 +554,7 @@
bind:checked={trustDevice}
style:accent-color={primaryColor}
/>
<span>Diesem Gerät 30 Tage vertrauen</span>
<span>{t.twoFactorTrustDevice}</span>
</label>
{/if}
@ -534,7 +566,7 @@
style:border-color={primaryColor}
style:color={isDark ? '#fff' : '#000'}
>
{loading ? 'Prüfe...' : 'Bestätigen'}
{loading ? t.twoFactorVerifying : t.twoFactorConfirm}
</button>
</form>
@ -548,7 +580,7 @@
clearError();
}}
>
{useBackupCode ? 'Authenticator-App verwenden' : 'Backup-Code verwenden'}
{useBackupCode ? t.twoFactorUseAuthenticator : t.twoFactorUseBackupCode}
</button>
<button
@ -562,7 +594,7 @@
clearError();
}}
>
Zurück zum Login
{t.twoFactorBackToLogin}
</button>
{:else}
{#if showVerifiedBanner}
@ -661,13 +693,11 @@
<Warning size={24} />
</div>
<div class="flex flex-col gap-1">
<p class="font-semibold text-[0.9rem]">Konto vorübergehend gesperrt</p>
<p class="font-semibold text-[0.9rem]">{t.accountLocked}</p>
<p class="text-[0.8rem] opacity-90">
Zu viele fehlgeschlagene Anmeldeversuche.
{t.tooManyAttempts}
{#if rateLimitCountdown > 0}
Erneut versuchen in <strong>{formatCountdown(rateLimitCountdown)}</strong>
{:else}
Du kannst es jetzt erneut versuchen.
{t.retryIn} <strong>{formatCountdown(rateLimitCountdown)}</strong>
{/if}
</p>
<button
@ -676,7 +706,7 @@
onclick={() => goto(forgotPasswordPath)}
style:color={primaryColor}
>
Passwort zurücksetzen
{t.resetPassword}
</button>
</div>
</div>
@ -703,7 +733,8 @@
{/if}
{#if rateLimitCountdown > 0}
<p class="font-semibold mt-1">
Erneut versuchen in {formatCountdown(rateLimitCountdown)}
{t.retryIn}
{formatCountdown(rateLimitCountdown)}
</p>
{/if}
</div>
@ -846,7 +877,7 @@
aria-live="polite"
>
<Check size={18} class="text-green-500 shrink-0" />
<p>Login-Link an {email} gesendet!</p>
<p>{t.magicLinkSent?.replace('{email}', email)}</p>
<button
type="button"
class="absolute right-2 top-1/2 -translate-y-1/2 bg-transparent border-none text-green-500 text-xl cursor-pointer p-1 leading-none opacity-70 hover:opacity-100"
@ -864,7 +895,7 @@
class="w-full bg-transparent border-none cursor-pointer font-medium text-sm p-3 text-center transition-opacity hover:opacity-70 disabled:opacity-40 disabled:cursor-not-allowed"
style:color={primaryColor}
>
{sendingMagicLink ? 'Wird gesendet...' : 'Login-Link per E-Mail senden'}
{sendingMagicLink ? t.magicLinkSending : t.magicLinkButton}
</button>
{/if}
{/if}

View file

@ -61,6 +61,8 @@ export interface AuthResult {
success: boolean;
error?: string;
needsVerification?: boolean;
twoFactorRedirect?: boolean;
retryAfter?: number;
}
/**