deploy / deploy (push) Successful in 36s
D'après les 16 vérifications de sécurité (vidéo) : - Double authentification (application d'authentification, TOTP), optionnelle dans Réglages → Mon compte ; code demandé à la connexion ; imposée côté serveur (migration 20261128160000, appliquée) : règles RLS restrictives, administration, actions sociales et fonctions Edge (delete-account redéployée) - Inscription avec une adresse déjà utilisée : même réponse qu'une inscription normale (aucune fuite) - « +1 » : un double tap involontaire ne compte qu'un épisode - Dépendances : correctifs de sécurité appliqués, versions exactes figées (.npmrc save-exact) - Déploiement : jeton du job limité à la lecture du dépôt - Logo « Kino » restant sur l'écran de connexion et l'invitation à créer un compte corrigé - Vérifiés sans changement : délais sur tous les appels réseau, aucun secret dans le navigateur, pas de redirection libre, en-têtes HTTPS / CSP stricts, boutons sensibles déjà protégés Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
354 lines
13 KiB
TypeScript
354 lines
13 KiB
TypeScript
import { t } from '../i18n'
|
|
import { LanguageSelect } from '../i18n/react'
|
|
import { Eye, EyeOff, Loader2 } from 'lucide-react'
|
|
import { useEffect, useState, type FormEvent, type ReactNode } from 'react'
|
|
import { PASSWORD_MIN, requestPasswordReset, signIn, signInWithGoogle, signOut, signUp, updatePassword, verifyTotp } from '../lib/cloud/auth'
|
|
import { USERNAME_RE } from '../lib/cloud/social'
|
|
import { cx } from '../lib/utils'
|
|
import { RANDOM_USERNAME } from './social/WelcomeProfile'
|
|
|
|
type Mode = 'login' | 'signup' | 'forgot'
|
|
|
|
function PasswordField({ value, onChange, placeholder, autoComplete }: { value: string; onChange: (v: string) => void; placeholder: string; autoComplete: string }) {
|
|
const [show, setShow] = useState(false)
|
|
return (
|
|
<div className="relative">
|
|
<input
|
|
className="field pe-11"
|
|
type={show ? 'text' : 'password'}
|
|
value={value}
|
|
onChange={(e) => onChange(e.target.value)}
|
|
placeholder={placeholder}
|
|
autoComplete={autoComplete}
|
|
minLength={PASSWORD_MIN}
|
|
maxLength={72}
|
|
required
|
|
/>
|
|
<button type="button" onClick={() => setShow((v) => !v)} className="absolute end-3 top-1/2 -translate-y-1/2 text-ink-3" aria-label={show ? t('auth.hidePassword') : t('auth.showPassword')}>
|
|
{show ? <EyeOff size={17} /> : <Eye size={17} />}
|
|
</button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function Shell({ children, subtitle }: { children: ReactNode; subtitle: string }) {
|
|
return (
|
|
<div className="safe-top safe-bottom flex min-h-dvh flex-col items-center justify-center bg-bg px-5 py-10">
|
|
<div className="w-full max-w-sm">
|
|
<h1 className="text-center text-[2.4rem] font-bold leading-none">
|
|
Bobin<span className="text-accent">oo</span>
|
|
</h1>
|
|
<p className="mt-3 text-center text-sm text-ink-3">{subtitle}</p>
|
|
<div className="mt-9">{children}</div>
|
|
<div className="mt-10 flex justify-center">
|
|
<LanguageSelect className="rounded-md border border-line bg-transparent px-3 py-1.5 text-xs text-ink-3" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
/** Écran de connexion / inscription (affiché quand les comptes sont activés et qu'on n'est pas connecté). */
|
|
export default function AuthScreen({ notice, onExplore, initialMode = 'login' }: { notice?: string; /** Mode découverte : regarder l'app sans compte */ onExplore?: () => void; initialMode?: 'login' | 'signup' }) {
|
|
const [mode, setMode] = useState<Mode>(initialMode)
|
|
const [email, setEmail] = useState('')
|
|
const [username, setUsername] = useState('')
|
|
const [password, setPassword] = useState('')
|
|
const [confirm, setConfirm] = useState('')
|
|
const [busy, setBusy] = useState(false)
|
|
const [error, setError] = useState<string>()
|
|
const [info, setInfo] = useState<string | undefined>(notice)
|
|
const cleanUsername = username.trim().replace(/^@/, '').toLowerCase()
|
|
const usernameOk = USERNAME_RE.test(cleanUsername) && !RANDOM_USERNAME.test(cleanUsername)
|
|
|
|
// Retour arrière depuis Google (page restaurée du cache) : les boutons ne restent pas bloqués
|
|
useEffect(() => {
|
|
const onShow = (e: PageTransitionEvent) => {
|
|
if (e.persisted) setBusy(false)
|
|
}
|
|
window.addEventListener('pageshow', onShow)
|
|
return () => window.removeEventListener('pageshow', onShow)
|
|
}, [])
|
|
|
|
const switchTo = (m: Mode) => {
|
|
setMode(m)
|
|
setError(undefined)
|
|
setInfo(undefined)
|
|
}
|
|
|
|
const google = async () => {
|
|
setError(undefined)
|
|
setInfo(undefined)
|
|
setBusy(true)
|
|
try {
|
|
await signInWithGoogle()
|
|
} catch (err) {
|
|
setError((err as Error).message)
|
|
setBusy(false)
|
|
}
|
|
}
|
|
|
|
const submit = async (e: FormEvent) => {
|
|
e.preventDefault()
|
|
setError(undefined)
|
|
setInfo(undefined)
|
|
if (mode === 'signup' && !usernameOk) return setError(t('social.usernameRule'))
|
|
if (mode === 'signup' && password !== confirm) return setError(t('auth.mismatch'))
|
|
setBusy(true)
|
|
try {
|
|
if (mode === 'login') await signIn(email, password)
|
|
else if (mode === 'signup') {
|
|
const needsConfirm = await signUp(email, password, cleanUsername)
|
|
if (needsConfirm) {
|
|
setInfo(t('auth.created', { email: email.trim() }))
|
|
setMode('login')
|
|
setPassword('')
|
|
setConfirm('')
|
|
}
|
|
} else {
|
|
await requestPasswordReset(email)
|
|
setInfo(t('auth.resetSent'))
|
|
setMode('login')
|
|
}
|
|
} catch (err) {
|
|
setError((err as Error).message)
|
|
} finally {
|
|
setBusy(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Shell subtitle={t('auth.tagline')}>
|
|
{mode !== 'forgot' && (
|
|
<div className="mb-5 grid grid-cols-2 gap-1 rounded-md border border-line p-1">
|
|
{(['login', 'signup'] as const).map((m) => (
|
|
<button
|
|
key={m}
|
|
type="button"
|
|
onClick={() => switchTo(m)}
|
|
className={cx('rounded-md py-2 text-sm font-medium transition-colors', mode === m ? 'bg-ink text-bg' : 'text-ink-3')}
|
|
>
|
|
{m === 'login' ? t('auth.loginTab') : t('auth.signupTab')}
|
|
</button>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
{mode !== 'forgot' && (
|
|
<>
|
|
<button type="button" onClick={google} disabled={busy} className="btn btn-ghost w-full py-3">
|
|
{t('auth.google')}
|
|
</button>
|
|
<div className="my-5 flex items-center gap-3 text-xs text-ink-3">
|
|
<span className="h-px flex-1 bg-line" />
|
|
{t('auth.or')}
|
|
<span className="h-px flex-1 bg-line" />
|
|
</div>
|
|
</>
|
|
)}
|
|
|
|
<form onSubmit={submit} className="space-y-3">
|
|
{mode === 'forgot' && <h2 className="mb-1 text-lg font-semibold">{t('auth.forgotTitle')}</h2>}
|
|
{mode === 'signup' && (
|
|
<div>
|
|
<div className="relative">
|
|
<span className="pointer-events-none absolute start-3.5 top-1/2 -translate-y-1/2 text-ink-3">@</span>
|
|
<input
|
|
className="field ps-8"
|
|
value={username}
|
|
onChange={(e) => setUsername(e.target.value.toLowerCase())}
|
|
placeholder={t('welcome.usernamePh')}
|
|
aria-label={t('social.username')}
|
|
autoComplete="username"
|
|
autoCapitalize="off"
|
|
spellCheck={false}
|
|
maxLength={21}
|
|
required
|
|
/>
|
|
</div>
|
|
<p className={cx('mt-1.5 text-xs', username && !usernameOk ? 'text-accent' : 'text-ink-3')}>{t('social.usernameRule')}</p>
|
|
</div>
|
|
)}
|
|
<input
|
|
className="field"
|
|
type="email"
|
|
value={email}
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
placeholder={t('auth.email')}
|
|
autoComplete="email"
|
|
inputMode="email"
|
|
autoCapitalize="off"
|
|
spellCheck={false}
|
|
maxLength={320}
|
|
required
|
|
/>
|
|
{mode !== 'forgot' && (
|
|
<PasswordField value={password} onChange={setPassword} placeholder={t('auth.password')} autoComplete={mode === 'login' ? 'current-password' : 'new-password'} />
|
|
)}
|
|
{mode === 'signup' && (
|
|
<>
|
|
<PasswordField value={confirm} onChange={setConfirm} placeholder={t('auth.confirmPassword')} autoComplete="new-password" />
|
|
<p className="text-xs text-ink-3">{t('auth.minChars', { n: PASSWORD_MIN })}</p>
|
|
</>
|
|
)}
|
|
|
|
{error && (
|
|
<p role="alert" className="rounded-xl border border-accent px-3 py-2.5 text-sm text-ink">
|
|
{error}
|
|
</p>
|
|
)}
|
|
{info && (
|
|
<p role="status" className="rounded-xl border border-line-strong px-3 py-2.5 text-sm text-ink-2">
|
|
{info}
|
|
</p>
|
|
)}
|
|
|
|
<button type="submit" disabled={busy} className="btn btn-primary w-full py-3">
|
|
{busy && <Loader2 size={17} className="animate-spin" />}
|
|
{mode === 'login' ? t('auth.login') : mode === 'signup' ? t('auth.signup') : t('auth.sendLink')}
|
|
</button>
|
|
{mode === 'signup' && <p className="text-center text-xs leading-relaxed text-ink-3">{t('auth.consent')}</p>}
|
|
</form>
|
|
|
|
{onExplore && mode !== 'forgot' && (
|
|
<button type="button" onClick={onExplore} className="mt-4 w-full rounded-md py-2.5 text-sm font-medium text-ink-2 transition-colors hover:text-ink">
|
|
{t('guest.explore')} <span className="text-accent rtl:-scale-x-100">→</span>
|
|
</button>
|
|
)}
|
|
|
|
<div className="mt-5 text-center text-sm">
|
|
{mode === 'login' && (
|
|
<button type="button" onClick={() => switchTo('forgot')} className="text-ink-3">
|
|
{t('auth.forgot')}
|
|
</button>
|
|
)}
|
|
{mode === 'forgot' && (
|
|
<button type="button" onClick={() => switchTo('login')} className="text-ink-3">
|
|
← {t('auth.backToLogin')}
|
|
</button>
|
|
)}
|
|
</div>
|
|
|
|
<p className="mt-10 text-center text-[11px] leading-relaxed text-ink-3">
|
|
{t('auth.privacy')}
|
|
</p>
|
|
<LegalLinks />
|
|
</Shell>
|
|
)
|
|
}
|
|
|
|
/** Choix d'un nouveau mot de passe (après le lien « mot de passe oublié »). */
|
|
export function NewPasswordScreen({ onDone }: { onDone: () => void }) {
|
|
const [password, setPassword] = useState('')
|
|
const [confirm, setConfirm] = useState('')
|
|
const [busy, setBusy] = useState(false)
|
|
const [error, setError] = useState<string>()
|
|
|
|
const submit = async (e: FormEvent) => {
|
|
e.preventDefault()
|
|
if (password !== confirm) return setError(t('auth.mismatch'))
|
|
setBusy(true)
|
|
setError(undefined)
|
|
try {
|
|
await updatePassword(password)
|
|
onDone()
|
|
} catch (err) {
|
|
setError((err as Error).message)
|
|
} finally {
|
|
setBusy(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Shell subtitle={t('auth.newPasswordTitle')}>
|
|
<form onSubmit={submit} className="space-y-3">
|
|
<PasswordField value={password} onChange={setPassword} placeholder={t('auth.newPassword')} autoComplete="new-password" />
|
|
<PasswordField value={confirm} onChange={setConfirm} placeholder={t('auth.confirmPassword')} autoComplete="new-password" />
|
|
<p className="text-xs text-ink-3">{t('auth.minChars', { n: PASSWORD_MIN })}</p>
|
|
{error && (
|
|
<p role="alert" className="rounded-xl border border-accent px-3 py-2.5 text-sm">
|
|
{error}
|
|
</p>
|
|
)}
|
|
<button type="submit" disabled={busy} className="btn btn-primary w-full py-3">
|
|
{busy && <Loader2 size={17} className="animate-spin" />}
|
|
{t('common.save')}
|
|
</button>
|
|
</form>
|
|
</Shell>
|
|
)
|
|
}
|
|
|
|
/** Champ « code à 6 chiffres » (application d'authentification). */
|
|
export function TotpField({ value, onChange, autoFocus }: { value: string; onChange: (v: string) => void; autoFocus?: boolean }) {
|
|
return (
|
|
<input
|
|
className="field text-center text-xl tracking-[0.3em] tabular-nums"
|
|
inputMode="numeric"
|
|
autoComplete="one-time-code"
|
|
pattern="[0-9 ]{6,7}"
|
|
maxLength={7}
|
|
value={value}
|
|
onChange={(e) => onChange(e.target.value.replace(/[^0-9 ]/g, ''))}
|
|
placeholder={t('mfa.code')}
|
|
aria-label={t('mfa.code')}
|
|
autoFocus={autoFocus}
|
|
required
|
|
/>
|
|
)
|
|
}
|
|
|
|
/** Connexion d'un compte protégé par la double authentification : code de l'application d'authentification. */
|
|
export function MfaScreen({ factorId }: { factorId: string }) {
|
|
const [code, setCode] = useState('')
|
|
const [busy, setBusy] = useState(false)
|
|
const [error, setError] = useState<string>()
|
|
|
|
const submit = async (e: FormEvent) => {
|
|
e.preventDefault()
|
|
if (busy) return
|
|
setBusy(true)
|
|
setError(undefined)
|
|
try {
|
|
await verifyTotp(factorId, code)
|
|
} catch (err) {
|
|
setError((err as Error).message)
|
|
setCode('')
|
|
} finally {
|
|
setBusy(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Shell subtitle={t('mfa.title')}>
|
|
<form onSubmit={submit} className="space-y-3">
|
|
<p className="text-center text-sm text-ink-2">{t('mfa.loginText')}</p>
|
|
<TotpField value={code} onChange={setCode} autoFocus />
|
|
{error && (
|
|
<p role="alert" className="rounded-xl border border-accent px-3 py-2.5 text-sm">
|
|
{error}
|
|
</p>
|
|
)}
|
|
<button type="submit" disabled={busy || code.replace(/\s/g, '').length !== 6} className="btn btn-primary w-full py-3">
|
|
{busy && <Loader2 size={17} className="animate-spin" />}
|
|
{t('mfa.confirm')}
|
|
</button>
|
|
<button type="button" onClick={() => void signOut()} className="w-full py-2 text-sm text-ink-3 underline underline-offset-4">
|
|
{t('account.logout')}
|
|
</button>
|
|
</form>
|
|
</Shell>
|
|
)
|
|
}
|
|
|
|
/** Liens vers les pages légales (statiques, hors de l'app). */
|
|
export function LegalLinks() {
|
|
return (
|
|
<nav className="mt-4 flex flex-wrap justify-center gap-x-4 gap-y-1 text-[11px] text-ink-3">
|
|
<a href="/terms.html" target="_blank" rel="noopener" className="underline underline-offset-2">{t('legal.terms')}</a>
|
|
<a href="/privacy.html" target="_blank" rel="noopener" className="underline underline-offset-2">{t('legal.privacy')}</a>
|
|
<a href="/legal.html" target="_blank" rel="noopener" className="underline underline-offset-2">{t('legal.notice')}</a>
|
|
</nav>
|
|
)
|
|
}
|