feat(app): identity screens and /app shell — auth store, login/signup/reset flows, dashboard, account
- state/authStore: session subscription (initialize + onAuthStateChange), profile + roles load, recovery flag, URL failure; services/localeSync: profiles.locale <-> localeStore - routes: /login, /signup, /forgot-password, /reset-password, /auth/callback; guards RequireAuth (next=) and RedirectIfSignedIn; /app (dashboard), /app/account behind the guard - shell: AppLayout (desktop sidebar, light top bar, mobile drawer), SidebarNav, UserBadge, SignOutButton - account: personal / professional / preferences / security sections, one save each, Zod validation with i18n keys - ui: Icon, FormField, Notice, ButtonLink (buttonClassName shared), PasswordField, OAuthButtons (config-driven) - Home header: Mon espace / Se connecter when Supabase is configured; local tool routes untouched - i18n: auth.*, shell.*, dashboard.*, account.*, home.space.* in fr + en
This commit is contained in:
1 parent
0f7292f9b3
commit
c517ea267b
46 files changed
+2798
-11
No files matched your search
@@ -0,0 +1,78 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import Brand from '@/components/brand/Brand'
|
||||
import LanguageSwitcher from '@/components/brand/LanguageSwitcher'
|
||||
import Card from '@/components/ui/Card'
|
||||
import { useConfig } from '@/app/providers/ConfigProvider'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
export interface AuthLayoutProps {
|
||||
title: string
|
||||
subtitle?: string
|
||||
children: ReactNode
|
||||
/** Links under the card (switch between login / signup, back links). */
|
||||
footer?: ReactNode
|
||||
}
|
||||
|
||||
/**
|
||||
* Two columns on large screens: a warm brand panel and the form card. On
|
||||
* small screens the panel collapses to the logo above the card.
|
||||
*/
|
||||
export default function AuthLayout({
|
||||
title,
|
||||
subtitle,
|
||||
children,
|
||||
footer,
|
||||
}: AuthLayoutProps) {
|
||||
const cfg = useConfig()
|
||||
const t = useT()
|
||||
return (
|
||||
<div className="flex min-h-dvh flex-col lg:flex-row">
|
||||
<aside className="hidden lg:flex lg:w-[42%] lg:flex-col lg:justify-between bg-[var(--color-surface-strong)] px-12 py-10">
|
||||
<Link to="/" aria-label={t('common.home')} className="w-fit">
|
||||
<Brand size="lg" />
|
||||
</Link>
|
||||
<div className="max-w-md space-y-4">
|
||||
<p className="font-serif text-3xl leading-tight text-[var(--color-ink)]">
|
||||
{t('auth.brand_claim')}
|
||||
</p>
|
||||
<p className="text-sm leading-relaxed text-[var(--color-ink-muted)]">
|
||||
{t('auth.brand_note')}
|
||||
</p>
|
||||
</div>
|
||||
<p className="text-xs text-[var(--color-ink-muted)]">{cfg.tagline}</p>
|
||||
</aside>
|
||||
|
||||
<main className="flex flex-1 flex-col px-4 py-6 sm:px-8 sm:py-10">
|
||||
<div className="flex items-center justify-between lg:justify-end">
|
||||
<Link to="/" aria-label={t('common.home')} className="lg:hidden">
|
||||
<Brand size="md" />
|
||||
</Link>
|
||||
<LanguageSwitcher />
|
||||
</div>
|
||||
<div className="flex flex-1 items-center justify-center py-8">
|
||||
<div className="w-full max-w-md space-y-5">
|
||||
<Card as="section" className="p-6 sm:p-8 space-y-6">
|
||||
<header className="space-y-1">
|
||||
<h1 className="font-serif text-2xl sm:text-3xl text-[var(--color-ink)] [text-wrap:balance]">
|
||||
{title}
|
||||
</h1>
|
||||
{subtitle && (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
{subtitle}
|
||||
</p>
|
||||
)}
|
||||
</header>
|
||||
{children}
|
||||
</Card>
|
||||
{footer && (
|
||||
<div className="text-center text-sm text-[var(--color-ink-muted)] space-y-1">
|
||||
{footer}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Link, type LinkProps } from 'react-router-dom'
|
||||
|
||||
/** Accent link used under the auth cards. */
|
||||
export default function AuthLink({ className = '', ...rest }: LinkProps) {
|
||||
return (
|
||||
<Link
|
||||
className={`font-medium text-[var(--color-accent)] underline-offset-2 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] rounded ${className}`}
|
||||
{...rest}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { useState } from 'react'
|
||||
import { signInWithOAuth, type OAuthProvider } from '@faunosteo/supabase'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Icon from '@/components/ui/Icon'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
import { useConfig } from '@/app/providers/ConfigProvider'
|
||||
import { getSupabaseClient } from '@/lib/supabase'
|
||||
import { absoluteUrl, AUTH_CALLBACK_PATH } from '@/auth/redirects'
|
||||
import { useAuthFailureMessage } from '@/auth/useAuthFailureMessage'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
const LABEL: Record<OAuthProvider, string> = {
|
||||
google: 'auth.continue_with_google',
|
||||
apple: 'auth.continue_with_apple',
|
||||
}
|
||||
|
||||
/** One button per configured provider, with the "or" rule under them. Nothing when none is configured. */
|
||||
export default function OAuthButtons() {
|
||||
const { authProviders } = useConfig()
|
||||
const t = useT()
|
||||
const describe = useAuthFailureMessage()
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [pending, setPending] = useState<OAuthProvider | null>(null)
|
||||
|
||||
if (authProviders.length === 0) return null
|
||||
|
||||
async function start(provider: OAuthProvider) {
|
||||
const client = getSupabaseClient()
|
||||
if (!client) return
|
||||
setPending(provider)
|
||||
setError(null)
|
||||
try {
|
||||
await signInWithOAuth(client, provider, absoluteUrl(AUTH_CALLBACK_PATH))
|
||||
} catch (err) {
|
||||
setError(describe(err))
|
||||
setPending(null)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-2">
|
||||
{authProviders.map((provider) => (
|
||||
<Button
|
||||
key={provider}
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => start(provider)}
|
||||
disabled={pending !== null}
|
||||
className="gap-2"
|
||||
>
|
||||
<Icon name={provider} size={18} />
|
||||
{t(LABEL[provider])}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
{error && <Notice tone="error">{error}</Notice>}
|
||||
<div className="flex items-center gap-3 text-xs text-[var(--color-ink-muted)]">
|
||||
<span className="h-px flex-1 bg-[var(--color-border)]" />
|
||||
{t('auth.or')}
|
||||
<span className="h-px flex-1 bg-[var(--color-border)]" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { useState, type InputHTMLAttributes } from 'react'
|
||||
import Input from '@/components/ui/Input'
|
||||
import Icon from '@/components/ui/Icon'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
type Props = Omit<InputHTMLAttributes<HTMLInputElement>, 'type'>
|
||||
|
||||
/** Password input with a show/hide toggle; the toggle is a labelled button. */
|
||||
export default function PasswordField({ className = '', ...rest }: Props) {
|
||||
const [visible, setVisible] = useState(false)
|
||||
const t = useT()
|
||||
return (
|
||||
<div className="relative">
|
||||
<Input
|
||||
type={visible ? 'text' : 'password'}
|
||||
className={`pr-11 ${className}`}
|
||||
{...rest}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setVisible((v) => !v)}
|
||||
aria-label={visible ? t('auth.hide_password') : t('auth.show_password')}
|
||||
aria-pressed={visible}
|
||||
className="absolute inset-y-0 right-0 flex w-11 items-center justify-center rounded-r-lg text-[var(--color-ink-muted)] hover:text-[var(--color-ink)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
|
||||
>
|
||||
<Icon name={visible ? 'eye-off' : 'eye'} />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/** Shown on the auth screens when the deployment has no Supabase. */
|
||||
export default function UnavailableNotice() {
|
||||
const t = useT()
|
||||
const navigate = useNavigate()
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<Notice tone="info">
|
||||
<p className="font-medium">{t('auth.unavailable_title')}</p>
|
||||
<p>{t('auth.unavailable_description')}</p>
|
||||
</Notice>
|
||||
<Button variant="secondary" onClick={() => navigate('/')}>
|
||||
{t('auth.back_to_tool')}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user