@poadio/starter-next 0.0.0-stage → 0.1.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.
- package/.dockerignore +9 -0
- package/.env.example +8 -0
- package/Dockerfile +29 -0
- package/README.md +141 -2
- package/bun.lock +156 -0
- package/gitignore +37 -0
- package/next.config.ts +14 -0
- package/package.json +70 -4
- package/public/logo.svg +1 -0
- package/public/providers/google.svg +1 -0
- package/public/providers/keycloak.svg +1 -0
- package/scripts/dev.mjs +68 -0
- package/scripts/env.mjs +130 -0
- package/scripts/env.test.mjs +71 -0
- package/src/app/(auth)/login/login-form.tsx +258 -0
- package/src/app/(auth)/login/page.tsx +16 -0
- package/src/app/(auth)/mfa/mfa-form.tsx +55 -0
- package/src/app/(auth)/mfa/page.tsx +16 -0
- package/src/app/(auth)/reset/page.tsx +16 -0
- package/src/app/(auth)/reset/reset-form.tsx +51 -0
- package/src/app/app/account/account.css +36 -0
- package/src/app/app/account/account.tsx +476 -0
- package/src/app/app/account/page.tsx +18 -0
- package/src/app/app/dashboard.tsx +58 -0
- package/src/app/app/hello/[name]/page.tsx +38 -0
- package/src/app/app/layout.tsx +12 -0
- package/src/app/app/page.tsx +18 -0
- package/src/app/app/public/page.tsx +15 -0
- package/src/app/app/public/public-content.tsx +31 -0
- package/src/app/globals.css +271 -0
- package/src/app/home.css +186 -0
- package/src/app/home.tsx +92 -0
- package/src/app/icon.svg +1 -0
- package/src/app/layout.tsx +58 -0
- package/src/app/not-found.tsx +6 -0
- package/src/app/page.tsx +6 -0
- package/src/app/providers.tsx +24 -0
- package/src/app/setup/page.tsx +39 -0
- package/src/app/shell.css +752 -0
- package/src/app.meta.ts +41 -0
- package/src/components/brand.tsx +15 -0
- package/src/components/captcha.tsx +93 -0
- package/src/components/link-button.tsx +9 -0
- package/src/components/rich.tsx +14 -0
- package/src/components/shell/app-menu.tsx +127 -0
- package/src/components/shell/app-shell.tsx +268 -0
- package/src/components/shell/page-title.tsx +29 -0
- package/src/components/shell/switches.tsx +35 -0
- package/src/components/shell/use-layout.ts +123 -0
- package/src/core/auth.tsx +227 -0
- package/src/core/env.server.ts +27 -0
- package/src/core/env.tsx +46 -0
- package/src/core/guards.tsx +74 -0
- package/src/core/messages.ts +18 -0
- package/src/core/providers.ts +32 -0
- package/src/core/theme-script.ts +7 -0
- package/src/core/theme.tsx +37 -0
- package/src/i18n/client.tsx +47 -0
- package/src/i18n/en.ts +228 -0
- package/src/i18n/fr.ts +251 -0
- package/src/i18n/index.ts +38 -0
- package/src/i18n/server.ts +19 -0
- package/tsconfig.json +21 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { PoadCard, PoadIcon, PoadTag } from '@poadio/ui-react';
|
|
3
|
+
import { LinkButton } from '@/components/link-button';
|
|
4
|
+
import { Rich } from '@/components/rich';
|
|
5
|
+
import { useAuth } from '@/core/auth';
|
|
6
|
+
import { providerLabel } from '@/core/providers';
|
|
7
|
+
import { useT } from '@/i18n/client';
|
|
8
|
+
|
|
9
|
+
export function Dashboard() {
|
|
10
|
+
const auth = useAuth();
|
|
11
|
+
const t = useT();
|
|
12
|
+
const list = (auth.user?.app_metadata?.providers as string[] | undefined) ?? [];
|
|
13
|
+
const providers = list.length ? list.map(providerLabel).join(', ') : auth.user?.is_anonymous ? t('dashboard.anonymous') : '—';
|
|
14
|
+
const aal = auth.claims?.aal;
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<section className="page page-wide">
|
|
18
|
+
<h2 className="hello">{t('dashboard.hello', { name: auth.displayName })}</h2>
|
|
19
|
+
<p className="lead">
|
|
20
|
+
<Rich text={t('dashboard.lead')} />
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
<div className="cards">
|
|
24
|
+
<PoadCard header={t('dashboard.session')}>
|
|
25
|
+
<dl className="props">
|
|
26
|
+
<dt>{t('dashboard.address')}</dt>
|
|
27
|
+
<dd>{auth.user?.email || '—'}</dd>
|
|
28
|
+
<dt>{t('dashboard.signIn')}</dt>
|
|
29
|
+
<dd>{providers}</dd>
|
|
30
|
+
<dt>{t('dashboard.level')}</dt>
|
|
31
|
+
<dd>
|
|
32
|
+
<PoadTag severity={aal === 'aal2' ? 'success' : 'neutral'} value={aal ?? '—'} />
|
|
33
|
+
</dd>
|
|
34
|
+
<dt>{t('dashboard.role')}</dt>
|
|
35
|
+
<dd>{auth.claims?.role}</dd>
|
|
36
|
+
</dl>
|
|
37
|
+
</PoadCard>
|
|
38
|
+
|
|
39
|
+
<PoadCard header={t('dashboard.next')}>
|
|
40
|
+
<ul className="next">
|
|
41
|
+
<li>
|
|
42
|
+
<PoadIcon name="file-plus" size={15} /> <Rich text={t('dashboard.next1')} />
|
|
43
|
+
</li>
|
|
44
|
+
<li>
|
|
45
|
+
<PoadIcon name="menu" size={15} /> <Rich text={t('dashboard.next2')} />
|
|
46
|
+
</li>
|
|
47
|
+
<li>
|
|
48
|
+
<PoadIcon name="palette" size={15} /> <Rich text={t('dashboard.next3')} />
|
|
49
|
+
</li>
|
|
50
|
+
</ul>
|
|
51
|
+
<LinkButton variant="outline" size="sm" href="/app/account">
|
|
52
|
+
<PoadIcon name="user" size={15} /> {t('menu.myAccount')}
|
|
53
|
+
</LinkButton>
|
|
54
|
+
</PoadCard>
|
|
55
|
+
</div>
|
|
56
|
+
</section>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PoadCard } from '@poadio/ui-react';
|
|
2
|
+
import Link from 'next/link';
|
|
3
|
+
import { Rich } from '@/components/rich';
|
|
4
|
+
import { PageTitle } from '@/components/shell/page-title';
|
|
5
|
+
import { getT, titled } from '@/i18n/server';
|
|
6
|
+
|
|
7
|
+
export const generateMetadata = titled('title.hello');
|
|
8
|
+
|
|
9
|
+
/** Exemple de route dynamique : /app/hello/:name, le paramètre arrive dans params (composant serveur) */
|
|
10
|
+
export default async function HelloPage({ params }: { params: Promise<{ name: string }> }) {
|
|
11
|
+
const { name } = await params;
|
|
12
|
+
const t = await getT();
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
<PageTitle k="title.hello" />
|
|
16
|
+
<section className="page">
|
|
17
|
+
<p className="lead">
|
|
18
|
+
<Rich text={t('hello.lead')} />
|
|
19
|
+
</p>
|
|
20
|
+
<PoadCard>
|
|
21
|
+
<h2 className="hello">{t('hello.title', { name: safeDecode(name) })}</h2>
|
|
22
|
+
<p className="muted">
|
|
23
|
+
{t('hello.try')} <Link href="/app/hello/Ada">Ada</Link>, <Link href="/app/hello/Grace">Grace</Link> {t('hello.or')}{' '}
|
|
24
|
+
<Link href="/app/hello/Linus">Linus</Link>.
|
|
25
|
+
</p>
|
|
26
|
+
</PoadCard>
|
|
27
|
+
</section>
|
|
28
|
+
</>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function safeDecode(s: string): string {
|
|
33
|
+
try {
|
|
34
|
+
return decodeURIComponent(s);
|
|
35
|
+
} catch {
|
|
36
|
+
return s;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { Configured } from '@/core/guards';
|
|
3
|
+
import { AppShell } from '@/components/shell/app-shell';
|
|
4
|
+
|
|
5
|
+
/** Cadre de toutes les pages de app/ : rail, barre du haut, canevas */
|
|
6
|
+
export default function AppLayout({ children }: { children: ReactNode }) {
|
|
7
|
+
return (
|
|
8
|
+
<Configured>
|
|
9
|
+
<AppShell>{children}</AppShell>
|
|
10
|
+
</Configured>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -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 { Dashboard } from './dashboard';
|
|
5
|
+
|
|
6
|
+
export const generateMetadata = titled('title.dashboard');
|
|
7
|
+
|
|
8
|
+
/** Page d'accueil de l'application connectée : point de départ de vos propres pages */
|
|
9
|
+
export default function DashboardPage() {
|
|
10
|
+
return (
|
|
11
|
+
<>
|
|
12
|
+
<PageTitle k="title.dashboard" />
|
|
13
|
+
<SignedIn>
|
|
14
|
+
<Dashboard />
|
|
15
|
+
</SignedIn>
|
|
16
|
+
</>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PageTitle } from '@/components/shell/page-title';
|
|
2
|
+
import { titled } from '@/i18n/server';
|
|
3
|
+
import { PublicContent } from './public-content';
|
|
4
|
+
|
|
5
|
+
export const generateMetadata = titled('title.public');
|
|
6
|
+
|
|
7
|
+
/** Page du cadre ouverte à tous : pas de garde */
|
|
8
|
+
export default function PublicPage() {
|
|
9
|
+
return (
|
|
10
|
+
<>
|
|
11
|
+
<PageTitle k="title.public" />
|
|
12
|
+
<PublicContent />
|
|
13
|
+
</>
|
|
14
|
+
);
|
|
15
|
+
}
|