feat(app): admin and catalogue entries, step-up guard, MFA in Mon compte (V1-2.5 E, F)
Nav hint from own grants and roles (never a control); RequireCatalog, RequireAdmin (no admin read before aal2), Accès non autorisé page, placeholder routes; TOTP factor list, enrolment with QR and one-time secret, removal, inline step-up for aal2 actions, step-up in password reset; auth kind aal2_required. App 601, e2e:ui 227.
This commit is contained in:
1 parent
99488d71d9
commit
4744e28986
38 files changed
+1818
-55
No files matched your search
@@ -0,0 +1,159 @@
|
||||
import { useEffect, useRef, useState, type FormEvent } from 'react'
|
||||
import { enrollTotp, unenrollFactor, type TotpEnrolment } from '@faunosteo/supabase'
|
||||
import InlineStepUp from '@/components/auth/InlineStepUp'
|
||||
import TotpCodeForm from '@/components/auth/TotpCodeForm'
|
||||
import Button from '@/components/ui/Button'
|
||||
import FormField, { fieldDescribedBy } from '@/components/ui/FormField'
|
||||
import Input from '@/components/ui/Input'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
import {
|
||||
FACTOR_NAME_MAX_LENGTH,
|
||||
factorNameSchema,
|
||||
fieldErrors,
|
||||
type FieldErrors,
|
||||
} from '@/auth/validation'
|
||||
import { isAal2Required, useStepUp } from '@/auth/useStepUp'
|
||||
import { useMfaFailureMessage } from '@/auth/useMfaFailureMessage'
|
||||
import { getSupabaseClient } from '@/lib/supabase'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
export interface EnrolTotpProps {
|
||||
/** The factor is verified: the list is read again. */
|
||||
onDone: () => void
|
||||
/** Closed without verifying; the unverified factor it created is removed first. */
|
||||
onClose: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a TOTP factor (contract §5.6): name → enrol → QR code and the secret
|
||||
* for manual entry → a code from the authenticator → verified. The secret
|
||||
* lives in this component's state only: never in a store, storage or a log,
|
||||
* gone when it unmounts. An unverified factor it created is removed on
|
||||
* cancel, and on unmount as a fallback (a dormant factor is a path, §5.7.3).
|
||||
*/
|
||||
export default function EnrolTotp({ onDone, onClose }: EnrolTotpProps) {
|
||||
const t = useT()
|
||||
const describe = useMfaFailureMessage()
|
||||
const stepUp = useStepUp()
|
||||
const [name, setName] = useState('')
|
||||
const [errors, setErrors] = useState<FieldErrors<{ name: string }>>({})
|
||||
const [failure, setFailure] = useState<string | null>(null)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [enrolment, setEnrolment] = useState<TotpEnrolment | null>(null)
|
||||
const unverifiedId = useRef<string | null>(null)
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
const client = getSupabaseClient()
|
||||
const factorId = unverifiedId.current
|
||||
if (client && factorId) void unenrollFactor(client, factorId).catch(() => undefined)
|
||||
},
|
||||
[],
|
||||
)
|
||||
|
||||
async function enrol(friendlyName: string) {
|
||||
const client = getSupabaseClient()
|
||||
if (!client) return
|
||||
setFailure(null)
|
||||
setBusy(true)
|
||||
try {
|
||||
const created = await enrollTotp(client, friendlyName)
|
||||
unverifiedId.current = created.factorId
|
||||
setEnrolment(created)
|
||||
} catch (error) {
|
||||
// A verified factor exists and the session is aal1: step up, then enrol again.
|
||||
const opened = isAal2Required(error) && (await stepUp.open(() => void enrol(friendlyName)))
|
||||
if (!opened) setFailure(describe(error))
|
||||
}
|
||||
setBusy(false)
|
||||
}
|
||||
|
||||
function submitName(event: FormEvent) {
|
||||
event.preventDefault()
|
||||
const parsed = factorNameSchema.safeParse({ name })
|
||||
if (!parsed.success) {
|
||||
setErrors(fieldErrors(parsed.error))
|
||||
return
|
||||
}
|
||||
setErrors({})
|
||||
void enrol(parsed.data.name)
|
||||
}
|
||||
|
||||
function verified() {
|
||||
unverifiedId.current = null
|
||||
setEnrolment(null)
|
||||
onDone()
|
||||
}
|
||||
|
||||
async function cancel() {
|
||||
const client = getSupabaseClient()
|
||||
const factorId = unverifiedId.current
|
||||
unverifiedId.current = null
|
||||
setEnrolment(null)
|
||||
if (client && factorId) await unenrollFactor(client, factorId).catch(() => undefined)
|
||||
onClose()
|
||||
}
|
||||
|
||||
if (enrolment) {
|
||||
return (
|
||||
<div className="space-y-4 rounded-lg border border-[var(--color-border)] p-4">
|
||||
<p className="text-sm text-[var(--color-ink)]">{t('mfa.enrol.scan')}</p>
|
||||
{/* A data: URI built by supabase-js, shown as an image: no markup enters the page. */}
|
||||
<img
|
||||
src={enrolment.qrCode}
|
||||
alt={t('mfa.enrol.qr_alt')}
|
||||
width={192}
|
||||
height={192}
|
||||
className="h-48 w-48 rounded-lg border border-[var(--color-border)] bg-white p-2"
|
||||
/>
|
||||
<div className="space-y-1">
|
||||
<p className="text-sm font-medium text-[var(--color-ink)]">{t('mfa.enrol.secret_label')}</p>
|
||||
<p className="text-xs text-[var(--color-ink-muted)]">{t('mfa.enrol.secret_hint')}</p>
|
||||
<code className="block break-all rounded-md bg-[var(--color-surface-strong)] px-3 py-2 font-mono text-sm text-[var(--color-ink)]">
|
||||
{enrolment.secret}
|
||||
</code>
|
||||
</div>
|
||||
<TotpCodeForm
|
||||
factors={[{ id: enrolment.factorId, friendlyName: name.trim() }]}
|
||||
onVerified={verified}
|
||||
onCancel={() => void cancel()}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4 rounded-lg border border-[var(--color-border)] p-4">
|
||||
{stepUp.challenge ? (
|
||||
<InlineStepUp challenge={stepUp.challenge} />
|
||||
) : (
|
||||
<form onSubmit={submitName} noValidate className="space-y-4">
|
||||
<FormField
|
||||
id="factor-name"
|
||||
label={t('mfa.enrol.name')}
|
||||
hint={t('mfa.enrol.name_hint')}
|
||||
error={errors.name && t(errors.name).replace('{max}', String(FACTOR_NAME_MAX_LENGTH))}
|
||||
>
|
||||
<Input
|
||||
id="factor-name"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
autoComplete="off"
|
||||
aria-invalid={Boolean(errors.name)}
|
||||
aria-describedby={fieldDescribedBy('factor-name', 'hint', errors.name)}
|
||||
/>
|
||||
</FormField>
|
||||
{failure && <Notice tone="error">{failure}</Notice>}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button type="submit" disabled={busy}>
|
||||
{busy ? t('mfa.enrol.creating') : t('mfa.enrol.continue')}
|
||||
</Button>
|
||||
<Button type="button" variant="ghost" onClick={onClose} disabled={busy}>
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { listTotpFactors, unenrollFactor, type TotpFactor } from '@faunosteo/supabase'
|
||||
import InlineStepUp from '@/components/auth/InlineStepUp'
|
||||
import { factorLabel } from '@/components/auth/TotpCodeForm'
|
||||
import Badge from '@/components/ui/Badge'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Dialog from '@/components/ui/Dialog'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
import EnrolTotp from './EnrolTotp'
|
||||
import { isAal2Required, useStepUp } from '@/auth/useStepUp'
|
||||
import { useMfaFailureMessage } from '@/auth/useMfaFailureMessage'
|
||||
import { getSupabaseClient } from '@/lib/supabase'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
type ListState =
|
||||
| { status: 'loading' }
|
||||
| { status: 'ready'; factors: TotpFactor[] }
|
||||
| { status: 'error'; error: unknown }
|
||||
|
||||
/** The account's TOTP factors, verified and unverified, read from GoTrue on open and after each change. */
|
||||
function useFactorList() {
|
||||
const [state, setState] = useState<ListState>({ status: 'loading' })
|
||||
const [reload, setReload] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
let live = true
|
||||
const client = getSupabaseClient()
|
||||
if (!client) return
|
||||
listTotpFactors(client)
|
||||
.then((factors) => {
|
||||
if (live) setState({ status: 'ready', factors })
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
if (live) setState({ status: 'error', error })
|
||||
})
|
||||
return () => {
|
||||
live = false
|
||||
}
|
||||
}, [reload])
|
||||
|
||||
return { state, refresh: () => setReload((n) => n + 1) }
|
||||
}
|
||||
|
||||
function FactorRow({ factor, onRemove }: { factor: TotpFactor; onRemove: () => void }) {
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const verified = factor.status === 'verified'
|
||||
return (
|
||||
<li className="flex flex-wrap items-center justify-between gap-3 py-3">
|
||||
<div className="min-w-0 space-y-1">
|
||||
<p className="flex flex-wrap items-center gap-2 text-sm font-medium text-[var(--color-ink)]">
|
||||
<span className="break-words">{factorLabel(factor, t('mfa.factor.unnamed'))}</span>
|
||||
<Badge tone={verified ? 'accent' : 'warn'}>
|
||||
{t(verified ? 'mfa.factor.verified' : 'mfa.factor.unverified')}
|
||||
</Badge>
|
||||
</p>
|
||||
<p className="text-xs text-[var(--color-ink-muted)]">
|
||||
{t('mfa.factor.added_on').replace(
|
||||
'{date}',
|
||||
new Date(factor.createdAt).toLocaleDateString(locale),
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<Button type="button" variant="secondary" onClick={onRemove}>
|
||||
{t('mfa.factor.remove')}
|
||||
</Button>
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Double authentification in Mon compte, Sécurité (contract §5.6): the
|
||||
* factor list, adding one, removing one after a confirmation. GoTrue's `aal2`
|
||||
* requirements (a second factor, removing a verified one) open the step-up
|
||||
* in place; the action is then sent again, never worked around.
|
||||
*/
|
||||
export default function MfaFactors() {
|
||||
const t = useT()
|
||||
const describe = useMfaFailureMessage()
|
||||
const stepUp = useStepUp()
|
||||
const { state, refresh } = useFactorList()
|
||||
const [enrolling, setEnrolling] = useState(false)
|
||||
const [toRemove, setToRemove] = useState<TotpFactor | null>(null)
|
||||
const [removing, setRemoving] = useState(false)
|
||||
const [failure, setFailure] = useState<string | null>(null)
|
||||
const [notice, setNotice] = useState<string | null>(null)
|
||||
|
||||
async function remove(factor: TotpFactor) {
|
||||
const client = getSupabaseClient()
|
||||
if (!client) return
|
||||
setFailure(null)
|
||||
setRemoving(true)
|
||||
try {
|
||||
await unenrollFactor(client, factor.id)
|
||||
setNotice(t('mfa.factor.removed'))
|
||||
refresh()
|
||||
} catch (error) {
|
||||
const opened = isAal2Required(error) && (await stepUp.open(() => void remove(factor)))
|
||||
if (!opened) setFailure(describe(error))
|
||||
}
|
||||
setRemoving(false)
|
||||
setToRemove(null)
|
||||
}
|
||||
|
||||
function enrolled() {
|
||||
setEnrolling(false)
|
||||
setNotice(t('mfa.enrol.done'))
|
||||
refresh()
|
||||
}
|
||||
|
||||
function closeEnrolment() {
|
||||
setEnrolling(false)
|
||||
refresh()
|
||||
}
|
||||
|
||||
const factors = state.status === 'ready' ? state.factors : []
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<p className="text-sm font-medium text-[var(--color-ink)]">
|
||||
{t('account.security.mfa_title')}
|
||||
</p>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">{t('mfa.description')}</p>
|
||||
</div>
|
||||
{state.status === 'loading' && (
|
||||
<p role="status" className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('mfa.factor.loading')}
|
||||
</p>
|
||||
)}
|
||||
{state.status === 'error' && (
|
||||
<div className="space-y-2">
|
||||
<Notice tone="error">{describe(state.error)}</Notice>
|
||||
<Button type="button" variant="secondary" onClick={refresh}>
|
||||
{t('common.retry')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{state.status === 'ready' && factors.length === 0 && (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">{t('mfa.factor.none')}</p>
|
||||
)}
|
||||
{factors.length > 0 && (
|
||||
<ul aria-label={t('mfa.factor.list_label')} className="divide-y divide-[var(--color-border)]">
|
||||
{factors.map((factor) => (
|
||||
<FactorRow key={factor.id} factor={factor} onRemove={() => setToRemove(factor)} />
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{stepUp.challenge && <InlineStepUp challenge={stepUp.challenge} />}
|
||||
{failure && <Notice tone="error">{failure}</Notice>}
|
||||
{notice && <Notice tone="success">{notice}</Notice>}
|
||||
{enrolling ? (
|
||||
<EnrolTotp onDone={enrolled} onClose={closeEnrolment} />
|
||||
) : (
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
setNotice(null)
|
||||
setFailure(null)
|
||||
setEnrolling(true)
|
||||
}}
|
||||
>
|
||||
{t('mfa.enrol.start')}
|
||||
</Button>
|
||||
)}
|
||||
<Dialog
|
||||
open={toRemove !== null}
|
||||
onClose={() => setToRemove(null)}
|
||||
title={t('mfa.remove.title')}
|
||||
description={
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('mfa.remove.body').replace(
|
||||
'{name}',
|
||||
toRemove ? factorLabel(toRemove, t('mfa.factor.unnamed')) : '',
|
||||
)}
|
||||
</p>
|
||||
}
|
||||
size="sm"
|
||||
>
|
||||
<div className="mt-4 flex justify-end gap-2">
|
||||
<Button type="button" variant="ghost" onClick={() => setToRemove(null)} disabled={removing}>
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="danger"
|
||||
onClick={() => toRemove && void remove(toRemove)}
|
||||
disabled={removing}
|
||||
>
|
||||
{t('mfa.remove.confirm')}
|
||||
</Button>
|
||||
</div>
|
||||
</Dialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
import { useState, type FormEvent } from 'react'
|
||||
import { updatePassword } from '@faunosteo/supabase'
|
||||
import InlineStepUp from '@/components/auth/InlineStepUp'
|
||||
import PasswordField from '@/components/auth/PasswordField'
|
||||
import Button from '@/components/ui/Button'
|
||||
import FormField, { fieldDescribedBy } from '@/components/ui/FormField'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
import SignOutButton from '@/components/shell/SignOutButton'
|
||||
import MfaFactors from './MfaFactors'
|
||||
import SectionCard from './SectionCard'
|
||||
import {
|
||||
fieldErrors,
|
||||
@@ -13,6 +15,7 @@ import {
|
||||
type FieldErrors,
|
||||
} from '@/auth/validation'
|
||||
import { useAuthFailureMessage } from '@/auth/useAuthFailureMessage'
|
||||
import { isAal2Required, useStepUp } from '@/auth/useStepUp'
|
||||
import { getSupabaseClient } from '@/lib/supabase'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
@@ -27,29 +30,38 @@ function ChangePasswordForm() {
|
||||
const [errors, setErrors] = useState<FieldErrors<Values>>({})
|
||||
const [failure, setFailure] = useState<string | null>(null)
|
||||
const [state, setState] = useState<State>('idle')
|
||||
const stepUp = useStepUp()
|
||||
|
||||
async function submit(e: FormEvent) {
|
||||
e.preventDefault()
|
||||
async function save(password: string) {
|
||||
const client = getSupabaseClient()
|
||||
const parsed = newPasswordSchema.safeParse(values)
|
||||
if (!client) return
|
||||
setFailure(null)
|
||||
setState('saving')
|
||||
try {
|
||||
await updatePassword(client, password)
|
||||
setValues({ password: '', passwordConfirm: '' })
|
||||
setState('saved')
|
||||
} catch (err) {
|
||||
// With a verified factor GoTrue wants aal2 (IDENTITY.md §4.1): step up, then send it again.
|
||||
const opened = isAal2Required(err) && (await stepUp.open(() => void save(password)))
|
||||
if (!opened) setFailure(describe(err))
|
||||
setState('idle')
|
||||
}
|
||||
}
|
||||
|
||||
function submit(e: FormEvent) {
|
||||
e.preventDefault()
|
||||
const parsed = newPasswordSchema.safeParse(values)
|
||||
if (!parsed.success) {
|
||||
setErrors(fieldErrors(parsed.error))
|
||||
return
|
||||
}
|
||||
setErrors({})
|
||||
setFailure(null)
|
||||
setState('saving')
|
||||
try {
|
||||
await updatePassword(client, parsed.data.password)
|
||||
setValues({ password: '', passwordConfirm: '' })
|
||||
setState('saved')
|
||||
} catch (err) {
|
||||
setFailure(describe(err))
|
||||
setState('idle')
|
||||
}
|
||||
void save(parsed.data.password)
|
||||
}
|
||||
|
||||
if (stepUp.challenge) return <InlineStepUp challenge={stepUp.challenge} />
|
||||
|
||||
return (
|
||||
<form onSubmit={submit} noValidate className="space-y-4">
|
||||
<FormField
|
||||
@@ -113,14 +125,7 @@ export default function SecurityPanel() {
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">{email}</p>
|
||||
</div>
|
||||
<ChangePasswordForm />
|
||||
<div className="rounded-lg border border-dashed border-[var(--color-border)] p-4">
|
||||
<p className="text-sm font-medium text-[var(--color-ink)]">
|
||||
{t('account.security.mfa_title')}
|
||||
</p>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{t('account.security.mfa_note')}
|
||||
</p>
|
||||
</div>
|
||||
<MfaFactors />
|
||||
<div className="space-y-2 border-t border-[var(--color-border)] pt-4">
|
||||
<p className="text-xs text-[var(--color-ink-muted)]">
|
||||
{t('account.security.sign_out_everywhere_note')}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import Notice from '@/components/ui/Notice'
|
||||
import TotpCodeForm from './TotpCodeForm'
|
||||
import type { StepUpChallenge } from '@/auth/useStepUp'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/** GoTrue asked for `aal2`: the reason, then the challenge in place; the action resumes once it succeeds. */
|
||||
export default function InlineStepUp({ challenge }: { challenge: StepUpChallenge }) {
|
||||
const t = useT()
|
||||
return (
|
||||
<div className="space-y-3 rounded-lg border border-[var(--color-border)] p-4">
|
||||
<Notice tone="info">{t('mfa.step_up.required')}</Notice>
|
||||
<TotpCodeForm {...challenge} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import { useId, useState, type FormEvent } from 'react'
|
||||
import { verifyTotp, type TotpFactor } from '@faunosteo/supabase'
|
||||
import Button from '@/components/ui/Button'
|
||||
import FormField, { fieldDescribedBy } from '@/components/ui/FormField'
|
||||
import Input from '@/components/ui/Input'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
import Select from '@/components/ui/Select'
|
||||
import { fieldErrors, totpCodeSchema, type FieldErrors } from '@/auth/validation'
|
||||
import { useMfaFailureMessage } from '@/auth/useMfaFailureMessage'
|
||||
import { getSupabaseClient } from '@/lib/supabase'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/** A factor the code may come from: the account's verified ones, or the one being enrolled. */
|
||||
export type CodeFactor = Pick<TotpFactor, 'id' | 'friendlyName'>
|
||||
|
||||
export interface TotpCodeFormProps {
|
||||
/** At least one; a choice is offered when there are several. */
|
||||
factors: CodeFactor[]
|
||||
/** Called once GoTrue accepted the code: the session is `aal2` from now on. */
|
||||
onVerified: () => void
|
||||
onCancel?: () => void
|
||||
}
|
||||
|
||||
/** The name a factor is listed under, or the generic one when it has none. */
|
||||
export function factorLabel(factor: CodeFactor, fallback: string): string {
|
||||
return factor.friendlyName ?? fallback
|
||||
}
|
||||
|
||||
/**
|
||||
* A 6-digit TOTP code, challenged and verified by GoTrue: the step-up
|
||||
* challenge (contract §5.6) with a verified factor, or the verification of a
|
||||
* factor being enrolled. Success upgrades this session to `aal2`
|
||||
* (supabase-js then emits the new session to the store). The code is never
|
||||
* kept once sent.
|
||||
*/
|
||||
export default function TotpCodeForm({ factors, onVerified, onCancel }: TotpCodeFormProps) {
|
||||
const t = useT()
|
||||
const describe = useMfaFailureMessage()
|
||||
const id = useId()
|
||||
const [factorId, setFactorId] = useState(factors[0]?.id ?? '')
|
||||
const [code, setCode] = useState('')
|
||||
const [errors, setErrors] = useState<FieldErrors<{ code: string }>>({})
|
||||
const [failure, setFailure] = useState<string | null>(null)
|
||||
const [busy, setBusy] = useState(false)
|
||||
|
||||
async function submit(event: FormEvent) {
|
||||
event.preventDefault()
|
||||
const client = getSupabaseClient()
|
||||
const parsed = totpCodeSchema.safeParse({ code })
|
||||
if (!client) return
|
||||
if (!parsed.success) {
|
||||
setErrors(fieldErrors(parsed.error))
|
||||
return
|
||||
}
|
||||
setErrors({})
|
||||
setFailure(null)
|
||||
setBusy(true)
|
||||
try {
|
||||
await verifyTotp(client, factorId, parsed.data.code)
|
||||
setCode('')
|
||||
onVerified()
|
||||
} catch (error) {
|
||||
setCode('')
|
||||
setFailure(describe(error))
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
const codeId = `${id}-code`
|
||||
return (
|
||||
<form onSubmit={submit} noValidate className="space-y-4">
|
||||
{factors.length > 1 && (
|
||||
<FormField id={`${id}-factor`} label={t('mfa.step_up.factor')}>
|
||||
<Select
|
||||
id={`${id}-factor`}
|
||||
value={factorId}
|
||||
onChange={(e) => setFactorId(e.target.value)}
|
||||
>
|
||||
{factors.map((factor) => (
|
||||
<option key={factor.id} value={factor.id}>
|
||||
{factorLabel(factor, t('mfa.factor.unnamed'))}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</FormField>
|
||||
)}
|
||||
<FormField
|
||||
id={codeId}
|
||||
label={t('mfa.code.label')}
|
||||
hint={t('mfa.code.hint')}
|
||||
error={errors.code && t(errors.code)}
|
||||
>
|
||||
<Input
|
||||
id={codeId}
|
||||
value={code}
|
||||
onChange={(e) => setCode(e.target.value)}
|
||||
inputMode="numeric"
|
||||
autoComplete="one-time-code"
|
||||
maxLength={7}
|
||||
aria-invalid={Boolean(errors.code)}
|
||||
aria-describedby={fieldDescribedBy(codeId, 'hint', errors.code)}
|
||||
/>
|
||||
</FormField>
|
||||
{failure && <Notice tone="error">{failure}</Notice>}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button type="submit" disabled={busy}>
|
||||
{busy ? t('mfa.code.verifying') : t('mfa.code.verify')}
|
||||
</Button>
|
||||
{onCancel && (
|
||||
<Button type="button" variant="ghost" onClick={onCancel} disabled={busy}>
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import ButtonLink from '@/components/ui/ButtonLink'
|
||||
import Card from '@/components/ui/Card'
|
||||
import { usePageHeading } from '@/app/usePageHeading'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/**
|
||||
* « Accès non autorisé » (contract §5.3, BDR-094): what a catalogue or
|
||||
* administration page shows when the server refuses (`rights.*`, and
|
||||
* `not_found` under /app/anatomy), the same whether the sheet exists or not.
|
||||
* Nothing from the address is echoed.
|
||||
*/
|
||||
export default function AccessDenied() {
|
||||
const t = useT()
|
||||
const heading = usePageHeading()
|
||||
return (
|
||||
<Card as="section" className="space-y-3 p-5 sm:p-6">
|
||||
<h1 ref={heading} tabIndex={-1} className="outline-none font-serif text-2xl text-[var(--color-ink)]">
|
||||
{t('access_denied.title')}
|
||||
</h1>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">{t('access_denied.body')}</p>
|
||||
<ButtonLink to="/app" variant="secondary">
|
||||
{t('access_denied.back')}
|
||||
</ButtonLink>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { usePageHeading } from '@/app/usePageHeading'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/**
|
||||
* V1-2.5 placeholder: the heading of a catalogue or administration page that
|
||||
* a later slice of the step builds (G to I). It requests nothing.
|
||||
*/
|
||||
export default function PlaceholderPage({ titleKey }: { titleKey: string }) {
|
||||
const t = useT()
|
||||
const heading = usePageHeading()
|
||||
return (
|
||||
<h1 ref={heading} tabIndex={-1} className="outline-none font-serif text-2xl sm:text-3xl text-[var(--color-ink)]">
|
||||
{t(titleKey)}
|
||||
</h1>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
import { Fragment } from 'react'
|
||||
import { NavLink } from 'react-router-dom'
|
||||
import Icon, { type IconName } from '@/components/ui/Icon'
|
||||
import { navigationHint, type NavigationHint } from '@/auth/navigationHint'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
interface NavItem {
|
||||
@@ -8,12 +11,24 @@ interface NavItem {
|
||||
labelKey: string
|
||||
hintKey?: string
|
||||
end?: boolean
|
||||
/** Shown only when this part of the navigation hint holds (V1-2, §11.1). */
|
||||
shownWhen?: keyof NavigationHint
|
||||
/** Set apart by a separator above and below, as on the validated board 10. */
|
||||
separated?: boolean
|
||||
}
|
||||
|
||||
export const NAV_ITEMS: readonly NavItem[] = [
|
||||
{ to: '/app', icon: 'dashboard', labelKey: 'shell.nav.dashboard', end: true },
|
||||
{ to: '/app/clients', icon: 'users', labelKey: 'shell.nav.clients' },
|
||||
{ to: '/app/animals', icon: 'paw', labelKey: 'shell.nav.animals' },
|
||||
{ to: '/app/anatomy', icon: 'book', labelKey: 'shell.nav.anatomy', shownWhen: 'catalog' },
|
||||
{
|
||||
to: '/app/admin',
|
||||
icon: 'shield',
|
||||
labelKey: 'shell.nav.admin',
|
||||
shownWhen: 'admin',
|
||||
separated: true,
|
||||
},
|
||||
{ to: '/app/account', icon: 'user', labelKey: 'shell.nav.account' },
|
||||
{
|
||||
to: '/',
|
||||
@@ -33,29 +48,41 @@ function linkClass(active: boolean): string {
|
||||
].join(' ')
|
||||
}
|
||||
|
||||
/** The destinations of the shell, in the validated mockup's order; `onNavigate` closes the mobile drawer. */
|
||||
/**
|
||||
* The destinations of the shell, in the validated mockup's order; `onNavigate`
|
||||
* closes the mobile drawer. « Fiches anatomiques » and « Administration » follow
|
||||
* the account's own grant rows and roles: hiding an entry protects nothing,
|
||||
* the pages act on the server's refusal.
|
||||
*/
|
||||
export default function SidebarNav({ onNavigate }: { onNavigate?: () => void }) {
|
||||
const t = useT()
|
||||
const grants = useAuthStore((s) => s.catalogGrants)
|
||||
const roles = useAuthStore((s) => s.roles)
|
||||
const hint = navigationHint(grants, roles)
|
||||
const items = NAV_ITEMS.filter((item) => !item.shownWhen || hint[item.shownWhen])
|
||||
return (
|
||||
<nav aria-label={t('shell.nav_label')} className="space-y-1">
|
||||
{NAV_ITEMS.map((item) => (
|
||||
<NavLink
|
||||
key={item.to}
|
||||
to={item.to}
|
||||
end={item.end}
|
||||
onClick={onNavigate}
|
||||
className={({ isActive }) => linkClass(isActive)}
|
||||
>
|
||||
<Icon name={item.icon} size={20} className="shrink-0" />
|
||||
<span className="flex min-w-0 flex-col leading-tight">
|
||||
<span className="truncate">{t(item.labelKey)}</span>
|
||||
{item.hintKey && (
|
||||
<span className="truncate text-xs font-normal text-[var(--color-ink-muted)]">
|
||||
{t(item.hintKey)}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</NavLink>
|
||||
{items.map((item) => (
|
||||
<Fragment key={item.to}>
|
||||
{item.separated && <hr className="my-3 border-[var(--color-border)]" />}
|
||||
<NavLink
|
||||
to={item.to}
|
||||
end={item.end}
|
||||
onClick={onNavigate}
|
||||
className={({ isActive }) => linkClass(isActive)}
|
||||
>
|
||||
<Icon name={item.icon} size={20} className="shrink-0" />
|
||||
<span className="flex min-w-0 flex-col leading-tight">
|
||||
<span className="truncate">{t(item.labelKey)}</span>
|
||||
{item.hintKey && (
|
||||
<span className="truncate text-xs font-normal text-[var(--color-ink-muted)]">
|
||||
{t(item.hintKey)}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</NavLink>
|
||||
{item.separated && <hr className="my-3 border-[var(--color-border)]" />}
|
||||
</Fragment>
|
||||
))}
|
||||
</nav>
|
||||
)
|
||||
|
||||
@@ -7,6 +7,8 @@ export type IconName =
|
||||
| 'user'
|
||||
| 'users'
|
||||
| 'paw'
|
||||
| 'book'
|
||||
| 'shield'
|
||||
| 'tool'
|
||||
| 'logout'
|
||||
| 'eye'
|
||||
@@ -24,6 +26,8 @@ const PATHS: Record<IconName, string> = {
|
||||
user: 'M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 16 0',
|
||||
users: 'M9 11a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM2 21a7 7 0 0 1 14 0M16 3.5a4 4 0 0 1 0 7M22 21a7 7 0 0 0-4.5-6.5',
|
||||
paw: 'M3.7 10.5a1.8 1.8 0 1 0 3.6 0 1.8 1.8 0 1 0-3.6 0M7.1 6.5a1.9 1.9 0 1 0 3.8 0 1.9 1.9 0 1 0-3.8 0M13.1 6.5a1.9 1.9 0 1 0 3.8 0 1.9 1.9 0 1 0-3.8 0M16.7 10.5a1.8 1.8 0 1 0 3.6 0 1.8 1.8 0 1 0-3.6 0M12 12.5c-2.5 0-5 3.2-5 5.3 0 1.6 1.3 2.4 2.8 2.4 1 0 1.5-.5 2.2-.5s1.2.5 2.2.5c1.5 0 2.8-.8 2.8-2.4 0-2.1-2.5-5.3-5-5.3z',
|
||||
book: 'M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2zM4 21V5M8 7h7M8 11h5',
|
||||
shield: 'M12 3l8 3v6c0 4.5-3.4 8-8 9-4.6-1-8-4.5-8-9V6zM9 12l2 2 4-4',
|
||||
tool: 'M14 3l7 7-4 4-7-7zM10 10l-6 6 4 4 6-6M3 21l3-3',
|
||||
logout: 'M10 4H5v16h5M15 8l5 4-5 4M20 12H9',
|
||||
eye: 'M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12zM12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z',
|
||||
|
||||
Reference in new issue
Block a user