From b826b05ce3873aa3615a81defda772edcda66bcc Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 23 Aug 2026 20:35:25 +0200 Subject: [PATCH] After resolving the issue of 2fa forget1 --- backend/src/repositories/userRepository.ts | 15 +++++++++++++-- backend/src/services/authService.ts | 18 ++++++++++++++++-- docs/DEPLOY-VPS.md | 8 ++++++++ .../src/features/profile/ProfilePage.tsx | 14 ++++++++++++++ prediqo_web/src/shared/i18n/locales/en.ts | 2 ++ prediqo_web/src/shared/i18n/locales/fr.ts | 2 ++ 6 files changed, 55 insertions(+), 4 deletions(-) diff --git a/backend/src/repositories/userRepository.ts b/backend/src/repositories/userRepository.ts index 5c463265..4cb67e78 100644 --- a/backend/src/repositories/userRepository.ts +++ b/backend/src/repositories/userRepository.ts @@ -766,10 +766,21 @@ export async function getSelfProfileForUser(userId: string): Promise { + if (!ciphertext) return null; + try { + return decrypt(ciphertext); + } catch (e) { + const detail = e instanceof Error ? e.message : String(e); + console.error(`[profile] Failed to decrypt ${field} for user ${userId}: ${detail}`); + return null; + } + }; + return { id: row.id, firstName: row.first_name ?? null, middleName: row.middle_name ?? null, lastName: row.last_name ?? null, dateOfBirth: dob != null ? (typeof dob === 'string' ? dob : (dob as Date).toISOString().slice(0, 10)) : null, - email: row.email_encrypted ? decrypt(row.email_encrypted) : null, - phone: row.phone_encrypted ? decrypt(row.phone_encrypted) : null, + email: safeDecrypt(row.email_encrypted, 'email'), + phone: safeDecrypt(row.phone_encrypted, 'phone'), countryOfResidence: row.country_of_residence ?? null, nationality: row.nationality ?? null, gender: (row.gender as UserGender | null) ?? null, diff --git a/docs/DEPLOY-VPS.md b/docs/DEPLOY-VPS.md index 1360c252..37d711d9 100644 --- a/docs/DEPLOY-VPS.md +++ b/docs/DEPLOY-VPS.md @@ -655,6 +655,14 @@ npm run phase-b:break-glass-reset-2fa -- \ 2. Profil → réactiver le 2FA → sauvegarder les **nouveaux** recovery codes. 3. Créer un second Super Admin si ce n’est pas déjà fait. +Si `/profile` affiche « Failed to load profile » alors que le login fonctionne, l’e-mail chiffré en base ne se déchiffre plus (souvent après changement d’`ENCRYPTION_KEY`). Mettez l’ancienne clé dans : + +```env +ENCRYPTION_KEY_PREVIOUS= +``` + +puis redémarrez le backend, ou déployez le correctif qui laisse `/me` charger même si le decrypt PII échoue (pour pouvoir réactiver le 2FA). Ensuite `npm run phase-b:…` / rebuild backend (+ rebuild `prediqo-web` si vous tirez le fix UI). + #### Sécurité | À faire | À éviter | diff --git a/prediqo_web/src/features/profile/ProfilePage.tsx b/prediqo_web/src/features/profile/ProfilePage.tsx index 5aaef568..4968663e 100644 --- a/prediqo_web/src/features/profile/ProfilePage.tsx +++ b/prediqo_web/src/features/profile/ProfilePage.tsx @@ -296,6 +296,20 @@ export function ProfilePage() { onSuccess={setToast} onError={setToast} /> + ) : profileQ.isError ? ( + + + {t('profile.loadError')} {t('profile.twoFactorRecoveryHint')} + + { + setToast(msg); + void profileQ.refetch(); + }} + onError={setToast} + /> + ) : ( )} diff --git a/prediqo_web/src/shared/i18n/locales/en.ts b/prediqo_web/src/shared/i18n/locales/en.ts index 45ed5ac9..2fd2a7db 100644 --- a/prediqo_web/src/shared/i18n/locales/en.ts +++ b/prediqo_web/src/shared/i18n/locales/en.ts @@ -538,6 +538,8 @@ export const en = { twoFactorAuth: 'Two-factor authentication', twoFactorHint: 'Protect your account with an authenticator app. Required for sensitive operations when enabled.', + twoFactorRecoveryHint: + 'You can still set up 2FA below. If email fields stay empty, ENCRYPTION_KEY may have changed — set ENCRYPTION_KEY_PREVIOUS to the old key, or update your email after 2FA is enabled.', securityNotifications: { title: 'Security activity', subtitle: 'Recent security events on your account (new sign-ins, password changes, 2FA updates).', diff --git a/prediqo_web/src/shared/i18n/locales/fr.ts b/prediqo_web/src/shared/i18n/locales/fr.ts index dc073638..389ff423 100644 --- a/prediqo_web/src/shared/i18n/locales/fr.ts +++ b/prediqo_web/src/shared/i18n/locales/fr.ts @@ -548,6 +548,8 @@ export const fr = { twoFactorAuth: 'Authentification à deux facteurs', twoFactorHint: 'Protégez votre compte avec une application d’authentification. Requis pour les opérations sensibles lorsqu’elle est activée.', + twoFactorRecoveryHint: + 'Vous pouvez quand même configurer le 2FA ci-dessous. Si l’e-mail reste vide, ENCRYPTION_KEY a peut-être changé — définissez ENCRYPTION_KEY_PREVIOUS avec l’ancienne clé, ou mettez à jour l’e-mail après avoir activé le 2FA.', securityNotifications: { title: 'Activité de sécurité', subtitle: