chahinebrini 5434254f74 feat(auth,mail): pw-reset OTP-flow + custom mail templates + account-switch cleanup
- Phase 3 PW-Reset: 3 screens (forgot-password → reset-otp → new-password),
  verifyOtp({type:'recovery'}), new updatePassword() action
- Custom Brevo-Mail templates (backend/public/templates/) — 5 HTMLs with
  go-template i18n (de/en/fr/ar incl. RTL for AR), OTP-only (no link),
  ReBreak branding
- signUp metadata.data.locale aus i18n.language → templates resolven Sprache
- Account-Switch-Bug fix: signOut() resettet alle 10 user-spezifischen stores
  + invalidateMe()
2026-05-19 10:49:23 +02:00

82 lines
2.2 KiB
TypeScript

import { create } from 'zustand';
import { apiFetch } from '../lib/api';
export type ProtectedDeviceStatus = 'pending' | 'active' | 'revoked' | 'degraded';
export interface ProtectedDevice {
id: string;
platform: 'mac' | 'windows' | string;
label: string;
status: ProtectedDeviceStatus;
installedAt: string | null;
createdAt: string;
}
export interface EnrollResult {
deviceId: string;
downloadUrl: string;
}
type ProtectedDevicesState = {
devices: ProtectedDevice[];
loading: boolean;
enrolling: boolean;
load: () => Promise<void>;
enroll: (label: string, platform: 'mac' | 'windows') => Promise<EnrollResult>;
confirmInstalled: (id: string) => Promise<void>;
remove: (id: string) => Promise<{ manualRemovalRequired: boolean }>;
reset: () => void;
};
export const useProtectedDevicesStore = create<ProtectedDevicesState>((set, get) => ({
devices: [],
loading: false,
enrolling: false,
load: async () => {
set({ loading: true });
try {
const res = await apiFetch<{ devices?: ProtectedDevice[] }>('/api/devices/protected');
set({ devices: Array.isArray(res?.devices) ? res.devices : [] });
} catch {
// endpoint might not be ready yet — keep empty state, screen handles it
} finally {
set({ loading: false });
}
},
enroll: async (label: string, platform: 'mac' | 'windows') => {
set({ enrolling: true });
try {
const result = await apiFetch<EnrollResult>('/api/devices/enroll', {
method: 'POST',
body: { platform, label },
});
await get().load();
return result;
} finally {
set({ enrolling: false });
}
},
confirmInstalled: async (id: string) => {
await apiFetch(`/api/devices/${id}/confirm-installed`, { method: 'POST' });
set((s) => ({
devices: s.devices.map((d) =>
d.id === id ? { ...d, status: 'active' as const, installedAt: new Date().toISOString() } : d
),
}));
},
remove: async (id: string) => {
const res = await apiFetch<{ manualRemovalRequired: boolean }>(`/api/devices/${id}/revoke`, {
method: 'DELETE',
});
set((s) => ({ devices: s.devices.filter((d) => d.id !== id) }));
return res;
},
reset: () => set({ devices: [], loading: false, enrolling: false }),
}));