From 9771d997f40136f93457699c8696d4ae9a8dbd6f Mon Sep 17 00:00:00 2001 From: bchanot Date: Sun, 11 Oct 2026 23:45:14 +0200 Subject: [PATCH] fix(app): failed sign-out reported (local session still cleared); reauthentication_needed phrased; docs(docs): exact production redirect allowlist --- .claude/tasks/contracts/2026-10-11-step-07-verify.md | 2 +- apps/app/src/components/shell/SignOutButton.tsx | 3 +++ apps/app/src/i18n/en.ts | 4 ++++ apps/app/src/i18n/fr.ts | 4 ++++ apps/app/src/state/authStore.ts | 11 ++++++++--- docs/development/IDENTITY.md | 7 ++++++- packages/supabase/src/auth.ts | 3 +++ 7 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.claude/tasks/contracts/2026-10-11-step-07-verify.md b/.claude/tasks/contracts/2026-10-11-step-07-verify.md index 05deee57..a7606a44 100644 --- a/.claude/tasks/contracts/2026-10-11-step-07-verify.md +++ b/.claude/tasks/contracts/2026-10-11-step-07-verify.md @@ -21,7 +21,7 @@ Implement Step 7 keeping the current visual identity (logo, palette, cream/white EXPECT: >= 4 ; passed 5. Server errors are never shown raw: every GoTrue error goes through classifyAuthError → AuthFailure kind → `auth.failure.` key present in fr and en for every kind of the union. CHECK: sed -n '/^export type AuthFailureKind =/,/^$/p' packages/supabase/src/auth.ts | grep -o "| '[a-z_]*'" | sed "s/| '//;s/'//" | sort -u > "$TMPDIR/kinds.txt"; for k in $(cat "$TMPDIR/kinds.txt"); do grep -q "'auth.failure.$k'" apps/app/src/i18n/fr.ts && grep -q "'auth.failure.$k'" apps/app/src/i18n/en.ts || echo MISSING $k; done - EXPECT: no MISSING line (12 kinds) + EXPECT: no MISSING line (13 kinds) 6. Email verification mandatory and password policy mirrored: config.toml enable_confirmations = true, minimum_password_length = 12, password_requirements lower_upper_letters_digits; client passwordSchema min 12 + the three classes. CHECK: grep -n "enable_confirmations = true\|minimum_password_length = 12\|lower_upper_letters_digits" supabase/config.toml | wc -l; grep -n "PASSWORD_MIN_LENGTH = 12\|\[a-z\]\|\[A-Z\]\|\[0-9\]" apps/app/src/auth/validation.ts | wc -l EXPECT: 3 ; >= 4 diff --git a/apps/app/src/components/shell/SignOutButton.tsx b/apps/app/src/components/shell/SignOutButton.tsx index d302cab2..a33c6860 100644 --- a/apps/app/src/components/shell/SignOutButton.tsx +++ b/apps/app/src/components/shell/SignOutButton.tsx @@ -15,6 +15,9 @@ export default function SignOutButton({ className = '' }: { className?: string } setBusy(true) try { await signOut() + } catch { + // The local session is cleared either way; the server may not have revoked the others. + window.alert(t('shell.sign_out_failed')) } finally { // The guard would redirect anyway; going home keeps the local tool one step away. navigate('/', { replace: true }) diff --git a/apps/app/src/i18n/en.ts b/apps/app/src/i18n/en.ts index c98d82f8..67b08aa1 100644 --- a/apps/app/src/i18n/en.ts +++ b/apps/app/src/i18n/en.ts @@ -275,6 +275,8 @@ export const en: Dict = { 'Too many attempts. Wait a few minutes before trying again.', 'auth.failure.link_expired': 'This link has expired or was already used.', 'auth.failure.session_expired': 'Your session has expired. Sign in again.', + 'auth.failure.reauthentication_needed': + 'For security, sign out and sign in again before changing the password.', 'auth.failure.provider_disabled': 'This sign-in method is not enabled.', 'auth.failure.network': 'Cannot reach the server. Check your network.', 'auth.failure.unknown': 'An unexpected error occurred. Try again.', @@ -289,6 +291,8 @@ export const en: Dict = { 'shell.nav.local_tool_hint': 'No account, PDF export', 'shell.sign_out': 'Sign out', 'shell.signing_out': 'Signing out…', + 'shell.sign_out_failed': + 'Signed out on this device, but the server did not confirm: your other sessions may stay open.', 'shell.loading_session': 'Checking your session…', 'shell.role.owner': 'Platform owner', 'shell.role.admin': 'Administrator', diff --git a/apps/app/src/i18n/fr.ts b/apps/app/src/i18n/fr.ts index a4b71367..e5dc3b28 100644 --- a/apps/app/src/i18n/fr.ts +++ b/apps/app/src/i18n/fr.ts @@ -291,6 +291,8 @@ export const fr: Dict = { 'Trop de tentatives. Patientez quelques minutes avant de réessayer.', 'auth.failure.link_expired': 'Ce lien a expiré ou a déjà été utilisé.', 'auth.failure.session_expired': 'Votre session a expiré. Reconnectez-vous.', + 'auth.failure.reauthentication_needed': + 'Par sécurité, déconnectez-vous puis reconnectez-vous avant de changer le mot de passe.', 'auth.failure.provider_disabled': "Ce mode de connexion n'est pas activé.", 'auth.failure.network': 'Connexion au serveur impossible. Vérifiez votre réseau.', 'auth.failure.unknown': "Une erreur inattendue s'est produite. Réessayez.", @@ -305,6 +307,8 @@ export const fr: Dict = { 'shell.nav.local_tool_hint': 'Sans compte, export PDF', 'shell.sign_out': 'Se déconnecter', 'shell.signing_out': 'Déconnexion…', + 'shell.sign_out_failed': + "Déconnecté sur cet appareil, mais le serveur n'a pas confirmé : vos autres sessions peuvent rester ouvertes.", 'shell.loading_session': 'Vérification de la session…', 'shell.role.owner': 'Propriétaire plateforme', 'shell.role.admin': 'Administrateur', diff --git a/apps/app/src/state/authStore.ts b/apps/app/src/state/authStore.ts index 2c0f1b83..ac5d2fb0 100644 --- a/apps/app/src/state/authStore.ts +++ b/apps/app/src/state/authStore.ts @@ -137,9 +137,7 @@ export const useAuthStore = create((set, get) => ({ }, signOut: async () => { - await signOutRequest(requireClient()) - // SIGNED_OUT also arrives through the subscription; this keeps the UI honest if it does not. - set({ + const clear = () => set({ status: 'signed_out', session: null, user: null, @@ -147,6 +145,13 @@ export const useAuthStore = create((set, get) => ({ roles: [], recovery: false, }) + try { + // auth-js clears the local session even when the server call fails. + await signOutRequest(requireClient()) + } finally { + // SIGNED_OUT also arrives through the subscription; this keeps the UI honest if it does not. + clear() + } }, clearRecovery: () => set({ recovery: false }), diff --git a/docs/development/IDENTITY.md b/docs/development/IDENTITY.md index 85a1075b..782b08ee 100644 --- a/docs/development/IDENTITY.md +++ b/docs/development/IDENTITY.md @@ -58,7 +58,12 @@ header shows "Se connecter" or "Mon espace". `https://.supabase.co/auth/v1/callback`; Apple needs a paid developer account and a Services ID (BACKEND_ARCHITECTURE §2); - `[auth.mfa.totp]` enrolment and verification are on server-side; -- redirect URLs allow `http://127.0.0.1:5173/**` and `http://localhost:5173/**`. +- redirect URLs allow `http://127.0.0.1:5173/**` and `http://localhost:5173/**` + (local only). On the hosted project the allowlist is exact, never a host + wildcard: Site URL `https://`, Redirect URLs + `https:///auth/callback` and `https:///reset-password`. + A broad pattern there turns `emailRedirectTo` / `redirectTo` into a + server-side open redirect. The app side: `APP_AUTH_PROVIDERS=google,apple` (Docker) or `VITE_AUTH_PROVIDERS` (dev) lists the buttons to show. Showing a button for a diff --git a/packages/supabase/src/auth.ts b/packages/supabase/src/auth.ts index 4b785bd6..84b1bab9 100644 --- a/packages/supabase/src/auth.ts +++ b/packages/supabase/src/auth.ts @@ -18,6 +18,7 @@ export type AuthFailureKind = | 'rate_limited' | 'link_expired' | 'session_expired' + | 'reauthentication_needed' | 'provider_disabled' | 'network' | 'unknown' @@ -49,6 +50,8 @@ const CODE_TO_KIND: Record = { session_expired: 'session_expired', session_not_found: 'session_expired', refresh_token_not_found: 'session_expired', + reauthentication_needed: 'reauthentication_needed', + reauthentication_not_valid: 'reauthentication_needed', provider_disabled: 'provider_disabled', oauth_provider_not_supported: 'provider_disabled', email_provider_disabled: 'provider_disabled',