@poadio/starter-next 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/.dockerignore +18 -0
  2. package/.env.example +8 -0
  3. package/Dockerfile +45 -0
  4. package/Dockerfile.dockerignore +18 -0
  5. package/README.md +197 -2
  6. package/bun.lock +156 -0
  7. package/gitignore +37 -0
  8. package/next.config.ts +14 -0
  9. package/package.json +72 -4
  10. package/public/logo.svg +1 -0
  11. package/public/providers/google.svg +1 -0
  12. package/public/providers/keycloak.svg +1 -0
  13. package/scripts/dev.mjs +92 -0
  14. package/scripts/env.mjs +160 -0
  15. package/scripts/env.test.mjs +93 -0
  16. package/src/app/(auth)/login/login-form.tsx +258 -0
  17. package/src/app/(auth)/login/page.tsx +16 -0
  18. package/src/app/(auth)/mfa/mfa-form.tsx +55 -0
  19. package/src/app/(auth)/mfa/page.tsx +16 -0
  20. package/src/app/(auth)/reset/page.tsx +16 -0
  21. package/src/app/(auth)/reset/reset-form.tsx +51 -0
  22. package/src/app/app/account/account.css +36 -0
  23. package/src/app/app/account/account.tsx +476 -0
  24. package/src/app/app/account/page.tsx +18 -0
  25. package/src/app/app/dashboard.tsx +58 -0
  26. package/src/app/app/hello/[name]/page.tsx +38 -0
  27. package/src/app/app/layout.tsx +12 -0
  28. package/src/app/app/page.tsx +18 -0
  29. package/src/app/app/public/page.tsx +15 -0
  30. package/src/app/app/public/public-content.tsx +31 -0
  31. package/src/app/globals.css +271 -0
  32. package/src/app/home.css +186 -0
  33. package/src/app/home.tsx +92 -0
  34. package/src/app/icon.svg +1 -0
  35. package/src/app/layout.tsx +59 -0
  36. package/src/app/not-found.tsx +6 -0
  37. package/src/app/page.tsx +6 -0
  38. package/src/app/providers.tsx +24 -0
  39. package/src/app/setup/page.tsx +39 -0
  40. package/src/app/shell.css +752 -0
  41. package/src/app.meta.ts +41 -0
  42. package/src/components/brand.tsx +15 -0
  43. package/src/components/captcha.tsx +93 -0
  44. package/src/components/link-button.tsx +9 -0
  45. package/src/components/rich.tsx +14 -0
  46. package/src/components/shell/app-menu.tsx +127 -0
  47. package/src/components/shell/app-shell.tsx +268 -0
  48. package/src/components/shell/page-title.tsx +29 -0
  49. package/src/components/shell/switches.tsx +35 -0
  50. package/src/components/shell/use-layout.ts +123 -0
  51. package/src/core/auth.tsx +228 -0
  52. package/src/core/env.server.ts +83 -0
  53. package/src/core/env.tsx +48 -0
  54. package/src/core/guards.tsx +74 -0
  55. package/src/core/messages.ts +18 -0
  56. package/src/core/providers.ts +32 -0
  57. package/src/core/theme-script.ts +7 -0
  58. package/src/core/theme.tsx +37 -0
  59. package/src/i18n/client.tsx +47 -0
  60. package/src/i18n/en.ts +228 -0
  61. package/src/i18n/fr.ts +251 -0
  62. package/src/i18n/index.ts +38 -0
  63. package/src/i18n/server.ts +19 -0
  64. package/tsconfig.json +21 -0
@@ -0,0 +1,55 @@
1
+ 'use client';
2
+ import { useState, type FormEvent } from 'react';
3
+ import { PoadButton, PoadCard, PoadField, PoadInput, PoadSelect } from '@poadio/ui-react';
4
+ import { useAuth } from '@/core/auth';
5
+ import { useT } from '@/i18n/client';
6
+
7
+ export function MfaForm() {
8
+ const auth = useAuth();
9
+ const t = useT();
10
+ const factors = (auth.user?.factors ?? [])
11
+ .filter((f) => f.status === 'verified')
12
+ .map((f) => ({ id: f.id, label: f.friendly_name || `TOTP ${f.id.slice(0, 8)}` }));
13
+ const [factorId, setFactorId] = useState<string | null>(factors[0]?.id ?? null);
14
+ const [code, setCode] = useState('');
15
+ const [busy, setBusy] = useState(false);
16
+
17
+ const verify = async (e: FormEvent) => {
18
+ e.preventDefault();
19
+ const id = factorId || factors[0]?.id;
20
+ if (!id || !auth.poad) return;
21
+ setBusy(true);
22
+ await auth.run(() => auth.poad!.auth.mfa.challengeAndVerify({ factorId: id, code }));
23
+ setBusy(false);
24
+ setCode('');
25
+ };
26
+
27
+ return (
28
+ <section className="auth">
29
+ <div className="auth-head">
30
+ <h1>{t('title.mfa')}</h1>
31
+ <p className="lead">{t('mfa.lead')}</p>
32
+ </div>
33
+ <PoadCard>
34
+ <form className="form" onSubmit={verify}>
35
+ {factors.length > 1 && (
36
+ <PoadField plain label={t('mfa.factor')}>
37
+ <PoadSelect options={factors} optionLabel="label" optionValue="id" value={factorId} onChange={(v) => setFactorId(v as string | null)} />
38
+ </PoadField>
39
+ )}
40
+ <PoadField label={t('common.code')} required>
41
+ <PoadInput mono name="code" value={code} onChange={(e) => setCode(e.target.value)} inputMode="numeric" autoComplete="one-time-code" maxLength={6} required autoFocus />
42
+ </PoadField>
43
+ <div className="row">
44
+ <PoadButton type="submit" loading={busy} disabled={code.length !== 6}>
45
+ {t('mfa.verify')}
46
+ </PoadButton>
47
+ <PoadButton type="button" variant="text" onClick={auth.signOut}>
48
+ {t('common.signOut')}
49
+ </PoadButton>
50
+ </div>
51
+ </form>
52
+ </PoadCard>
53
+ </section>
54
+ );
55
+ }
@@ -0,0 +1,16 @@
1
+ import { SignedIn } from '@/core/guards';
2
+ import { titled } from '@/i18n/server';
3
+ import { MfaForm } from './mfa-form';
4
+
5
+ export const generateMetadata = titled('title.mfa');
6
+
7
+ /** Second facteur demandé après la connexion (aal1 → aal2) */
8
+ export default function MfaPage() {
9
+ return (
10
+ <div className="screen">
11
+ <SignedIn mfa={false}>
12
+ <MfaForm />
13
+ </SignedIn>
14
+ </div>
15
+ );
16
+ }
@@ -0,0 +1,16 @@
1
+ import { SignedIn } from '@/core/guards';
2
+ import { titled } from '@/i18n/server';
3
+ import { ResetForm } from './reset-form';
4
+
5
+ export const generateMetadata = titled('title.reset');
6
+
7
+ /** Nouveau mot de passe, après le lien de réinitialisation */
8
+ export default function ResetPage() {
9
+ return (
10
+ <div className="screen">
11
+ <SignedIn mfa={false}>
12
+ <ResetForm />
13
+ </SignedIn>
14
+ </div>
15
+ );
16
+ }
@@ -0,0 +1,51 @@
1
+ 'use client';
2
+ import { useState, type FormEvent } from 'react';
3
+ import { useRouter } from 'next/navigation';
4
+ import { PoadButton, PoadCard, PoadField, PoadPassword } from '@poadio/ui-react';
5
+ import { HOME_SIGNED_IN, useAuth } from '@/core/auth';
6
+ import { useT } from '@/i18n/client';
7
+
8
+ export function ResetForm() {
9
+ const auth = useAuth();
10
+ const t = useT();
11
+ const router = useRouter();
12
+ const [password, setPassword] = useState('');
13
+ const [confirm, setConfirm] = useState('');
14
+ const [busy, setBusy] = useState(false);
15
+ const after = () => router.replace(auth.needsMfa ? '/mfa' : HOME_SIGNED_IN);
16
+
17
+ const save = async (e: FormEvent) => {
18
+ e.preventDefault();
19
+ setBusy(true);
20
+ const user = await auth.run(() => auth.poad!.auth.updateUser({ password }), t('reset.changed'));
21
+ setBusy(false);
22
+ if (user) after();
23
+ };
24
+
25
+ return (
26
+ <section className="auth">
27
+ <div className="auth-head">
28
+ <h1>{t('title.reset')}</h1>
29
+ <p className="lead">{t('reset.lead', { email: auth.user?.email ?? '' })}</p>
30
+ </div>
31
+ <PoadCard>
32
+ <form className="form" onSubmit={save}>
33
+ <PoadField plain label={t('reset.new')} required>
34
+ <PoadPassword name="password" value={password} onValueChange={setPassword} toggleMask feedback autoComplete="new-password" />
35
+ </PoadField>
36
+ <PoadField plain label={t('reset.confirm')} required error={confirm && confirm !== password ? t('reset.differ') : ''}>
37
+ <PoadPassword name="confirm" value={confirm} onValueChange={setConfirm} autoComplete="new-password" />
38
+ </PoadField>
39
+ <div className="row">
40
+ <PoadButton type="submit" loading={busy} disabled={!password || password !== confirm}>
41
+ {t('common.save')}
42
+ </PoadButton>
43
+ <PoadButton type="button" variant="text" onClick={after}>
44
+ {t('common.later')}
45
+ </PoadButton>
46
+ </div>
47
+ </form>
48
+ </PoadCard>
49
+ </section>
50
+ );
51
+ }
@@ -0,0 +1,36 @@
1
+ /* Mon compte (account.tsx) */
2
+ .account .logo {
3
+ width: 16px;
4
+ height: 16px;
5
+ }
6
+ .account .qr {
7
+ display: flex;
8
+ gap: 16px;
9
+ align-items: center;
10
+ flex-wrap: wrap;
11
+ }
12
+ .account .qr img {
13
+ width: 180px;
14
+ height: 180px;
15
+ background: #fff;
16
+ border-radius: 8px;
17
+ padding: 6px;
18
+ }
19
+ .account .list {
20
+ list-style: none;
21
+ margin: 0;
22
+ padding: 0;
23
+ display: flex;
24
+ flex-direction: column;
25
+ gap: 10px;
26
+ }
27
+ .account .list li {
28
+ display: flex;
29
+ align-items: center;
30
+ gap: 10px;
31
+ flex-wrap: wrap;
32
+ }
33
+ .account .list .grow {
34
+ flex: 1;
35
+ min-width: 12ch;
36
+ }
@@ -0,0 +1,476 @@
1
+ 'use client';
2
+ import { useCallback, useEffect, useMemo, useState, type FormEvent } from 'react';
3
+ import { PoadButton, PoadCard, PoadField, PoadIcon, PoadInput, PoadMessage, PoadPassword, PoadSelect, PoadTab, PoadTabs, PoadTag } from '@poadio/ui-react';
4
+ import type { Result, SessionInfo, TotpEnrollment, User } from '@poadio/client-js';
5
+ import { useAuth } from '@/core/auth';
6
+ import { providerLabel, providerLogo } from '@/core/providers';
7
+ import { useI18n } from '@/i18n/client';
8
+ import './account.css';
9
+
10
+ const submit = (fn: () => unknown) => (e: FormEvent) => {
11
+ e.preventDefault();
12
+ void fn();
13
+ };
14
+
15
+ /** Navigateur et système, lus grossièrement dans le user-agent */
16
+ function device(ua: string | null, unknown: string): string {
17
+ if (!ua) return unknown;
18
+ const browser = /Edg\//.test(ua)
19
+ ? 'Edge'
20
+ : /Firefox\//.test(ua)
21
+ ? 'Firefox'
22
+ : /Chrome\//.test(ua)
23
+ ? 'Chrome'
24
+ : /Safari\//.test(ua)
25
+ ? 'Safari'
26
+ : /node|undici/i.test(ua)
27
+ ? 'Node.js'
28
+ : ua.split(/[ /]/)[0];
29
+ const os = /Mac OS X/.test(ua) ? 'macOS' : /Windows/.test(ua) ? 'Windows' : /Android/.test(ua) ? 'Android' : /iPhone|iPad/.test(ua) ? 'iOS' : /Linux/.test(ua) ? 'Linux' : '';
30
+ return os ? `${browser} · ${os}` : browser;
31
+ }
32
+
33
+ export function Account() {
34
+ const auth = useAuth();
35
+ const user = auth.user;
36
+ // La garde <SignedIn> ne rend cette page qu'avec une session
37
+ return user ? <AccountTabs user={user} /> : null;
38
+ }
39
+
40
+ function AccountTabs({ user }: { user: User }) {
41
+ const auth = useAuth();
42
+ const { t, intl } = useI18n();
43
+ const poad = auth.poad!;
44
+ const [tab, setTab] = useState<unknown>('profile');
45
+ const [busy, setBusy] = useState<string | null>(null);
46
+ const date = (v: string | null | undefined, style: 'medium' | 'short' = 'medium') =>
47
+ v ? new Intl.DateTimeFormat(intl, { dateStyle: style, timeStyle: style === 'short' ? 'short' : 'medium' }).format(new Date(v)) : '—';
48
+
49
+ // Profil
50
+ const [name, setName] = useState(String(user.user_metadata['name'] ?? ''));
51
+ /** Langue des e-mails : vide = celle du navigateur */
52
+ const [locale, setLocale] = useState<string | null>(String(user.user_metadata['locale'] ?? ''));
53
+ const locales = [
54
+ { value: '', label: t('account.localeBrowser') },
55
+ { value: 'fr', label: 'Français' },
56
+ { value: 'en', label: 'English' },
57
+ ];
58
+
59
+ // Sécurité
60
+ const [newPassword, setNewPassword] = useState('');
61
+ const [nonce, setNonce] = useState('');
62
+ const [newEmail, setNewEmail] = useState('');
63
+ const [emailCode, setEmailCode] = useState('');
64
+ const [emailSentTo, setEmailSentTo] = useState<string | null>(null);
65
+
66
+ // MFA
67
+ const [factorName, setFactorName] = useState('');
68
+ const [enrollment, setEnrollment] = useState<TotpEnrollment | null>(null);
69
+ const [enrollCode, setEnrollCode] = useState('');
70
+ /**
71
+ * QR code en URL blob: — le service le donne en data:image/svg+xml non
72
+ * encodé, que le navigateur coupe au premier « # » (couleurs du SVG).
73
+ */
74
+ const qrUrl = useMemo(() => {
75
+ const qr = enrollment?.totp.qr_code;
76
+ if (!qr) return null;
77
+ const raw = qr.slice(qr.indexOf(',') + 1);
78
+ let svg = raw;
79
+ try {
80
+ svg = decodeURIComponent(raw);
81
+ } catch {
82
+ /* SVG brut, non encodé */
83
+ }
84
+ return URL.createObjectURL(new Blob([svg], { type: 'image/svg+xml' }));
85
+ }, [enrollment]);
86
+ useEffect(() => () => {
87
+ if (qrUrl) URL.revokeObjectURL(qrUrl);
88
+ }, [qrUrl]);
89
+
90
+ // Sessions
91
+ const [openSessions, setOpenSessions] = useState<SessionInfo[] | null>(null);
92
+
93
+ const factors = user.factors ?? [];
94
+ const identities = user.identities ?? [];
95
+ const linked = new Set(identities.map((i) => i.provider));
96
+ const linkable = auth.oauthProviders.filter((p) => !linked.has(p));
97
+ const aal = auth.claims?.aal;
98
+
99
+ const step = useCallback(
100
+ async <T,>(key: string, fn: () => Promise<Result<T>>, success?: string): Promise<T | null> => {
101
+ setBusy(key);
102
+ try {
103
+ return await auth.run(fn, success);
104
+ } finally {
105
+ setBusy(null);
106
+ }
107
+ },
108
+ [auth],
109
+ );
110
+
111
+ const loadSessions = useCallback(async () => {
112
+ const list = await step('sessions', () => poad.auth.listSessions());
113
+ if (list) setOpenSessions(list);
114
+ }, [step, poad]);
115
+
116
+ // Liste des sessions chargée à l'ouverture de l'onglet
117
+ useEffect(() => {
118
+ if (tab === 'session') void loadSessions();
119
+ // eslint-disable-next-line react-hooks/exhaustive-deps
120
+ }, [tab]);
121
+
122
+ const saveProfile = () => step('profile', () => poad.auth.updateUser({ data: { name, locale: locale || null } }), t('account.profileSaved'));
123
+
124
+ const changePassword = async () => {
125
+ const ok = await step('password', () => poad.auth.updateUser({ password: newPassword, nonce: nonce || undefined }), t('account.passwordChanged'));
126
+ if (ok) {
127
+ setNewPassword('');
128
+ setNonce('');
129
+ }
130
+ };
131
+
132
+ const changeEmail = async () => {
133
+ const ok = await step('email', () => poad.auth.updateUser({ email: newEmail }, { redirectTo: auth.redirect('/app/account') }), t('account.confirmationSent'));
134
+ if (ok) setEmailSentTo(newEmail);
135
+ };
136
+
137
+ const confirmEmail = async () => {
138
+ if (!emailSentTo) return;
139
+ const ok = await step('email', () => poad.auth.verifyOtp({ email: emailSentTo, token: emailCode, type: 'email_change' }), t('account.emailChanged'));
140
+ if (ok) {
141
+ setEmailSentTo(null);
142
+ setEmailCode('');
143
+ setNewEmail('');
144
+ }
145
+ };
146
+
147
+ const enroll = async () => {
148
+ const e = await step('enroll', () => poad.auth.mfa.enroll({ friendlyName: factorName || undefined }));
149
+ if (e) setEnrollment(e);
150
+ };
151
+
152
+ const confirmEnroll = async () => {
153
+ if (!enrollment) return;
154
+ const ok = await step('enroll', () => poad.auth.mfa.challengeAndVerify({ factorId: enrollment.id, code: enrollCode }), t('account.factorEnabled'));
155
+ if (ok) {
156
+ setEnrollment(null);
157
+ setEnrollCode('');
158
+ setFactorName('');
159
+ }
160
+ };
161
+
162
+ const cancelEnroll = async () => {
163
+ const e = enrollment;
164
+ setEnrollment(null);
165
+ if (e) await auth.run(() => poad.auth.mfa.unenroll(e.id));
166
+ };
167
+
168
+ const revokeSession = async (s: SessionInfo) => {
169
+ const ok = await step(`revoke-${s.id}`, () => poad.auth.revokeSession(s.id), s.current ? t('account.signedOut') : t('account.sessionClosed'));
170
+ if (ok && !s.current) await loadSessions();
171
+ };
172
+
173
+ const signOut = (scope: 'local' | 'others' | 'global') => {
174
+ const msg = { local: t('account.signedOut'), others: t('account.othersClosed'), global: t('account.allClosed') }[scope];
175
+ void step(`signout-${scope}`, () => poad.auth.signOut({ scope }), msg);
176
+ };
177
+
178
+ return (
179
+ <section className="page page-wide account">
180
+ <div className="row">
181
+ <h1>{(user.user_metadata['name'] as string) || user.email || t('account.anonymousAccount')}</h1>
182
+ {user.is_anonymous && <PoadTag value={t('account.anonymousTag')} severity="warning" size="sm" />}
183
+ {user.email_confirmed_at && <PoadTag value={t('account.confirmedTag')} severity="success" size="sm" />}
184
+ </div>
185
+
186
+ <PoadTabs value={tab} onValueChange={setTab} variant="line" scrollable>
187
+ {/* Profil */}
188
+ <PoadTab value="profile" label={t('account.tabProfile')} icon="user">
189
+ <div className="stack">
190
+ <PoadCard>
191
+ <dl className="props">
192
+ <dt>{t('account.id')}</dt>
193
+ <dd className="mono">{user.id}</dd>
194
+ <dt>{t('account.address')}</dt>
195
+ <dd>{user.email || '—'}</dd>
196
+ {user.new_email && (
197
+ <>
198
+ <dt>{t('account.newAddress')}</dt>
199
+ <dd>{t('account.pending', { email: user.new_email })}</dd>
200
+ </>
201
+ )}
202
+ <dt>{t('account.providers')}</dt>
203
+ <dd>{(user.app_metadata.providers ?? []).join(', ') || '—'}</dd>
204
+ <dt>{t('account.createdAt')}</dt>
205
+ <dd>{date(user.created_at)}</dd>
206
+ <dt>{t('account.lastSignIn')}</dt>
207
+ <dd>{date(user.last_sign_in_at)}</dd>
208
+ </dl>
209
+ </PoadCard>
210
+ <PoadCard header={t('account.metadata')}>
211
+ <form className="form" onSubmit={submit(saveProfile)}>
212
+ <PoadField label={t('common.name')} hint={t('account.nameHint')}>
213
+ <PoadInput name="name" value={name} onChange={(e) => setName(e.target.value)} />
214
+ </PoadField>
215
+ <PoadField plain label={t('account.locale')} hint={t('account.localeHint')}>
216
+ <PoadSelect options={locales} optionLabel="label" optionValue="value" value={locale} onChange={(v) => setLocale(v as string | null)} />
217
+ </PoadField>
218
+ <div className="row">
219
+ <PoadButton type="submit" loading={busy === 'profile'}>
220
+ {t('common.save')}
221
+ </PoadButton>
222
+ <PoadButton type="button" variant="text" loading={busy === 'reload'} onClick={() => void step('reload', () => poad.auth.getUser())}>
223
+ <PoadIcon name="refresh" size={16} /> {t('account.reload')}
224
+ </PoadButton>
225
+ </div>
226
+ </form>
227
+ </PoadCard>
228
+ </div>
229
+ </PoadTab>
230
+
231
+ {/* Sécurité */}
232
+ <PoadTab value="security" label={t('account.tabSecurity')} icon="lock">
233
+ <div className="stack">
234
+ {user.is_anonymous && (
235
+ <PoadMessage severity="info" variant="soft">
236
+ {t('account.anonymousHelp')}
237
+ </PoadMessage>
238
+ )}
239
+ <PoadCard header={user.is_anonymous ? t('account.addEmail') : t('account.changeEmail')}>
240
+ {emailSentTo ? (
241
+ <form className="form" onSubmit={submit(confirmEmail)}>
242
+ <p className="muted" style={{ margin: 0 }}>
243
+ {t('account.codeSentTo', { email: emailSentTo })}
244
+ </p>
245
+ <PoadField label={t('common.code')} required>
246
+ <PoadInput mono name="ecode" value={emailCode} onChange={(e) => setEmailCode(e.target.value)} inputMode="numeric" maxLength={6} autoComplete="one-time-code" />
247
+ </PoadField>
248
+ <div className="row">
249
+ <PoadButton type="submit" loading={busy === 'email'} disabled={emailCode.length !== 6}>
250
+ {t('account.confirm')}
251
+ </PoadButton>
252
+ <PoadButton type="button" variant="text" onClick={() => setEmailSentTo(null)}>
253
+ {t('common.cancel')}
254
+ </PoadButton>
255
+ </div>
256
+ </form>
257
+ ) : (
258
+ <form className="form" onSubmit={submit(changeEmail)}>
259
+ <PoadField label={t('account.newAddress')} required>
260
+ <PoadInput type="email" name="nemail" value={newEmail} onChange={(e) => setNewEmail(e.target.value)} autoComplete="email" />
261
+ </PoadField>
262
+ <PoadButton type="submit" loading={busy === 'email'} disabled={!newEmail}>
263
+ {t('account.sendConfirmation')}
264
+ </PoadButton>
265
+ </form>
266
+ )}
267
+ </PoadCard>
268
+ <PoadCard header={t('common.password')}>
269
+ <form className="form" onSubmit={submit(changePassword)}>
270
+ <PoadField plain label={t('account.newPassword')} required>
271
+ <PoadPassword name="npass" value={newPassword} onValueChange={setNewPassword} toggleMask feedback autoComplete="new-password" />
272
+ </PoadField>
273
+ <PoadField label={t('account.reauthCode')} optional optionalText={t('account.ifRequired')} hint={t('account.reauthHint')}>
274
+ <PoadInput mono name="nonce" value={nonce} onChange={(e) => setNonce(e.target.value)} inputMode="numeric" maxLength={6} />
275
+ </PoadField>
276
+ <div className="row">
277
+ <PoadButton type="submit" loading={busy === 'password'} disabled={!newPassword}>
278
+ {t('account.change')}
279
+ </PoadButton>
280
+ <PoadButton
281
+ type="button"
282
+ variant="text"
283
+ loading={busy === 'reauth'}
284
+ disabled={!user.email}
285
+ onClick={() => void step('reauth', () => poad.auth.reauthenticate(), t('account.codeSent'))}
286
+ >
287
+ {t('account.getCode')}
288
+ </PoadButton>
289
+ </div>
290
+ </form>
291
+ </PoadCard>
292
+ </div>
293
+ </PoadTab>
294
+
295
+ {/* MFA */}
296
+ <PoadTab value="mfa" label={t('account.tabMfa')} icon="shield" count={factors.length || null}>
297
+ <div className="stack">
298
+ <PoadCard header={t('account.totp')}>
299
+ <div className="form">
300
+ <div className="row">
301
+ <span className="muted">{t('account.sessionLevel')}</span>
302
+ <PoadTag value={aal ?? '—'} severity={aal === 'aal2' ? 'success' : 'neutral'} size="sm" />
303
+ </div>
304
+ {factors.length ? (
305
+ <>
306
+ <ul className="list">
307
+ {factors.map((f) => (
308
+ <li key={f.id}>
309
+ <PoadIcon name="smartphone" size={18} />
310
+ <span className="grow">
311
+ {f.friendly_name || 'TOTP'} <span className="muted mono">{f.id.slice(0, 8)}</span>
312
+ </span>
313
+ <PoadTag
314
+ value={f.status === 'verified' ? t('account.active') : t('account.unverified')}
315
+ severity={f.status === 'verified' ? 'success' : 'warning'}
316
+ size="sm"
317
+ />
318
+ <PoadButton
319
+ variant="text"
320
+ severity="danger"
321
+ size="sm"
322
+ loading={busy === `factor-${f.id}`}
323
+ onClick={() => void step(`factor-${f.id}`, () => poad.auth.mfa.unenroll(f.id), t('account.factorRemoved'))}
324
+ >
325
+ <PoadIcon name="trash-2" size={16} /> {t('account.remove')}
326
+ </PoadButton>
327
+ </li>
328
+ ))}
329
+ </ul>
330
+ {aal !== 'aal2' && (
331
+ <PoadMessage severity="warning" variant="soft" size="sm">
332
+ {t('account.aal2Required')}
333
+ </PoadMessage>
334
+ )}
335
+ </>
336
+ ) : (
337
+ <p className="muted" style={{ margin: 0 }}>
338
+ {t('account.noFactor')}
339
+ </p>
340
+ )}
341
+ </div>
342
+ </PoadCard>
343
+
344
+ <PoadCard header={t('account.addFactor')}>
345
+ {enrollment ? (
346
+ <form className="form" onSubmit={submit(confirmEnroll)}>
347
+ <div className="qr">
348
+ {/* eslint-disable-next-line @next/next/no-img-element */}
349
+ {qrUrl && <img src={qrUrl} alt={t('account.qrAlt')} />}
350
+ <div>
351
+ <p className="muted">{t('account.scan')}</p>
352
+ <p className="mono">{enrollment.totp.secret}</p>
353
+ </div>
354
+ </div>
355
+ <PoadField label={t('account.appCode')} required>
356
+ <PoadInput mono name="ecode" value={enrollCode} onChange={(e) => setEnrollCode(e.target.value)} inputMode="numeric" maxLength={6} autoComplete="one-time-code" />
357
+ </PoadField>
358
+ <div className="row">
359
+ <PoadButton type="submit" loading={busy === 'enroll'} disabled={enrollCode.length !== 6}>
360
+ {t('account.activate')}
361
+ </PoadButton>
362
+ <PoadButton type="button" variant="text" onClick={() => void cancelEnroll()}>
363
+ {t('common.cancel')}
364
+ </PoadButton>
365
+ </div>
366
+ </form>
367
+ ) : (
368
+ <form className="form" onSubmit={submit(enroll)}>
369
+ <PoadField label={t('account.factorName')} optional optionalText={t('common.optional')}>
370
+ <PoadInput name="fname" value={factorName} onChange={(e) => setFactorName(e.target.value)} placeholder={t('account.factorPlaceholder')} />
371
+ </PoadField>
372
+ <PoadButton type="submit" loading={busy === 'enroll'}>
373
+ <PoadIcon name="qr-code" size={16} /> {t('account.generateQr')}
374
+ </PoadButton>
375
+ </form>
376
+ )}
377
+ </PoadCard>
378
+ </div>
379
+ </PoadTab>
380
+
381
+ {/* Identités */}
382
+ <PoadTab value="identities" label={t('account.tabIdentities')} icon="link" count={identities.length || null}>
383
+ <div className="stack">
384
+ <PoadCard>
385
+ <ul className="list">
386
+ {identities.map((i) => (
387
+ <li key={i.identity_id}>
388
+ <PoadTag value={providerLabel(i.provider)} severity="info" size="sm" />
389
+ <span className="grow">{i.email || String(i.identity_data?.['email'] ?? '') || i.id}</span>
390
+ <span className="muted">{date(i.last_sign_in_at, 'short')}</span>
391
+ <PoadButton
392
+ variant="text"
393
+ severity="danger"
394
+ size="sm"
395
+ disabled={identities.length < 2}
396
+ loading={busy === `unlink-${i.identity_id}`}
397
+ onClick={() => void step(`unlink-${i.identity_id}`, () => poad.auth.unlinkIdentity(i.identity_id), t('account.identityRemoved'))}
398
+ >
399
+ <PoadIcon name="unlink" size={16} /> {t('account.remove')}
400
+ </PoadButton>
401
+ </li>
402
+ ))}
403
+ {!identities.length && <li className="muted">{t('account.noIdentity')}</li>}
404
+ </ul>
405
+ </PoadCard>
406
+ {linkable.length > 0 && (
407
+ <PoadCard header={t('account.linkProvider')}>
408
+ <div className="row">
409
+ {linkable.map((p) => {
410
+ const logo = providerLogo(p);
411
+ return (
412
+ <PoadButton
413
+ key={p}
414
+ variant="outline"
415
+ loading={busy === `link-${p}`}
416
+ onClick={() => void step(`link-${p}`, () => poad.auth.linkIdentity({ provider: p, redirectTo: auth.redirect('/app/account') }))}
417
+ >
418
+ {/* eslint-disable-next-line @next/next/no-img-element */}
419
+ {logo ? <img className="logo" src={logo} alt="" /> : <PoadIcon name="link" size={16} />} {providerLabel(p)}
420
+ </PoadButton>
421
+ );
422
+ })}
423
+ </div>
424
+ </PoadCard>
425
+ )}
426
+ </div>
427
+ </PoadTab>
428
+
429
+ {/* Session */}
430
+ <PoadTab value="session" label={t('account.tabSession')} icon="key-round">
431
+ <div className="stack">
432
+ <PoadCard header={t('account.signOutTitle')}>
433
+ <div className="row">
434
+ <PoadButton variant="outline" severity="danger" loading={busy === 'signout-local'} onClick={() => signOut('local')}>
435
+ {t('common.signOut')}
436
+ </PoadButton>
437
+ <PoadButton variant="outline" severity="danger" loading={busy === 'signout-others'} onClick={() => signOut('others')}>
438
+ {t('account.signOutOthers')}
439
+ </PoadButton>
440
+ <PoadButton variant="outline" severity="danger" loading={busy === 'signout-global'} onClick={() => signOut('global')}>
441
+ {t('account.signOutAll')}
442
+ </PoadButton>
443
+ </div>
444
+ </PoadCard>
445
+ <PoadCard header={t('account.openSessions')}>
446
+ <ul className="list">
447
+ {(openSessions ?? []).map((s) => (
448
+ <li key={s.id}>
449
+ <PoadIcon name={s.current ? 'check' : 'smartphone'} size={18} />
450
+ <span className="grow">
451
+ {device(s.user_agent, t('account.unknown'))}{' '}
452
+ <span className="muted">
453
+ · {s.ip || '—'} · {date(s.refreshed_at || s.created_at, 'short')}
454
+ </span>
455
+ </span>
456
+ {s.current && <PoadTag value={t('account.thisSession')} severity="success" size="sm" />}
457
+ <PoadTag value={s.aal} severity={s.aal === 'aal2' ? 'success' : 'neutral'} size="sm" />
458
+ <PoadButton variant="text" severity="danger" size="sm" loading={busy === `revoke-${s.id}`} onClick={() => void revokeSession(s)}>
459
+ <PoadIcon name="log-out" size={16} /> {t('account.close')}
460
+ </PoadButton>
461
+ </li>
462
+ ))}
463
+ {!openSessions?.length && <li className="muted">{openSessions ? t('account.noSession') : t('common.loading')}</li>}
464
+ </ul>
465
+ <div className="row" style={{ marginTop: 12 }}>
466
+ <PoadButton variant="text" size="sm" loading={busy === 'sessions'} onClick={() => void loadSessions()}>
467
+ <PoadIcon name="refresh" size={16} /> {t('account.refresh')}
468
+ </PoadButton>
469
+ </div>
470
+ </PoadCard>
471
+ </div>
472
+ </PoadTab>
473
+ </PoadTabs>
474
+ </section>
475
+ );
476
+ }
@@ -0,0 +1,18 @@
1
+ import { PageTitle } from '@/components/shell/page-title';
2
+ import { SignedIn } from '@/core/guards';
3
+ import { titled } from '@/i18n/server';
4
+ import { Account } from './account';
5
+
6
+ export const generateMetadata = titled('title.account');
7
+
8
+ /** Profil, sécurité, MFA (TOTP), identités, sessions */
9
+ export default function AccountPage() {
10
+ return (
11
+ <>
12
+ <PageTitle k="title.account" />
13
+ <SignedIn>
14
+ <Account />
15
+ </SignedIn>
16
+ </>
17
+ );
18
+ }