@payez/next-mvp 4.8.1 → 4.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/POST-INSTALL.md +408 -408
  2. package/README.md +859 -859
  3. package/dist/api-handlers/admin/audit.js +13 -21
  4. package/dist/api-handlers/admin/sessions.js +59 -45
  5. package/dist/api-handlers/admin/stats.js +1 -1
  6. package/dist/api-handlers/admin/users.js +15 -23
  7. package/dist/api-handlers/admin/vibe-data.d.ts +5 -0
  8. package/dist/api-handlers/admin/vibe-data.js +5 -0
  9. package/dist/components/account/MobileNavDrawer.js +18 -18
  10. package/dist/components/account/UserAvatarMenu.js +1 -1
  11. package/dist/components/admin/AlertSettingsTab.js +40 -40
  12. package/dist/components/admin/LoggingSettingsTab.js +28 -28
  13. package/dist/lib/session-store.js +21 -21
  14. package/dist/lib/startup-init.js +19 -19
  15. package/dist/pages/login/page.js +28 -28
  16. package/dist/pages/settings/EnhancedSettingsPage.js +17 -17
  17. package/dist/vibe/client.d.ts +1 -1
  18. package/dist/vibe/client.js +2 -1
  19. package/dist/vibe/filters.d.ts +36 -0
  20. package/dist/vibe/filters.js +47 -0
  21. package/dist/vibe/generic.js +2 -1
  22. package/dist/vibe/sessions.js +28 -3
  23. package/package.json +2 -2
  24. package/scripts/check-publish-eol.mjs +33 -15
  25. package/src/api/auth-handler.ts +550 -550
  26. package/src/api/index.ts +17 -17
  27. package/src/api-handlers/account/change-password.ts +170 -170
  28. package/src/api-handlers/account/masked-info.ts +46 -46
  29. package/src/api-handlers/account/profile.ts +99 -99
  30. package/src/api-handlers/account/recovery/forward.ts +117 -117
  31. package/src/api-handlers/account/recovery/initiate.ts +59 -59
  32. package/src/api-handlers/account/recovery/send-code.ts +21 -21
  33. package/src/api-handlers/account/recovery/verify-code.ts +20 -20
  34. package/src/api-handlers/account/reset-password.ts +87 -87
  35. package/src/api-handlers/account/send-code.ts +70 -70
  36. package/src/api-handlers/account/update-phone.ts +84 -84
  37. package/src/api-handlers/account/validate-password.ts +139 -139
  38. package/src/api-handlers/account/verify-email.ts +134 -134
  39. package/src/api-handlers/account/verify-sms.ts +134 -134
  40. package/src/api-handlers/admin/analytics.ts +452 -452
  41. package/src/api-handlers/admin/audit.ts +223 -232
  42. package/src/api-handlers/admin/index.ts +63 -63
  43. package/src/api-handlers/admin/redis-sessions.ts +259 -259
  44. package/src/api-handlers/admin/sessions.ts +341 -327
  45. package/src/api-handlers/admin/site-logs.ts +388 -388
  46. package/src/api-handlers/admin/stats.ts +260 -260
  47. package/src/api-handlers/admin/users.ts +240 -251
  48. package/src/api-handlers/admin/vibe-data.ts +338 -333
  49. package/src/api-handlers/anon/preferences.ts +123 -123
  50. package/src/api-handlers/auth/credential-login-email-code.ts +92 -92
  51. package/src/api-handlers/auth/credential-login.ts +948 -948
  52. package/src/api-handlers/auth/jwks.ts +31 -31
  53. package/src/api-handlers/auth/login.ts +252 -252
  54. package/src/api-handlers/auth/passkey-signin.ts +116 -116
  55. package/src/api-handlers/auth/refresh.ts +829 -829
  56. package/src/api-handlers/auth/signout.ts +201 -201
  57. package/src/api-handlers/auth/status.ts +23 -23
  58. package/src/api-handlers/auth/update-session.ts +144 -144
  59. package/src/api-handlers/auth/validate.ts +45 -45
  60. package/src/api-handlers/auth/verify-code.ts +116 -116
  61. package/src/api-handlers/mfa/backup-code-verify.ts +170 -170
  62. package/src/api-handlers/mfa/backup-codes.ts +42 -42
  63. package/src/api-handlers/mfa/methods.ts +47 -47
  64. package/src/api-handlers/mfa/totp-confirm.ts +43 -43
  65. package/src/api-handlers/mfa/totp-enroll.ts +43 -43
  66. package/src/api-handlers/mfa/totp-verify.ts +172 -172
  67. package/src/api-handlers/oauth/resume.ts +182 -182
  68. package/src/api-handlers/onboarding/send-email-code.ts +18 -18
  69. package/src/api-handlers/onboarding/set-password.ts +21 -21
  70. package/src/api-handlers/onboarding/verify-code.ts +20 -20
  71. package/src/api-handlers/onboarding/verify-welcome-email.ts +17 -17
  72. package/src/api-handlers/passkeys/list.ts +32 -32
  73. package/src/api-handlers/passkeys/manage.ts +55 -55
  74. package/src/api-handlers/passkeys/register-options.ts +43 -43
  75. package/src/api-handlers/passkeys/register-verify.ts +42 -42
  76. package/src/api-handlers/session/refresh-viability.ts +56 -56
  77. package/src/api-handlers/session/viability.ts +238 -238
  78. package/src/api-handlers/test/force-expire.ts +167 -167
  79. package/src/auth/auth-decision.ts +292 -292
  80. package/src/auth/better-auth.ts +1688 -1688
  81. package/src/auth/idp-oauth.ts +310 -310
  82. package/src/auth/password-reset-bridge.ts +98 -98
  83. package/src/auth/revocation-fields.ts +16 -16
  84. package/src/auth/route-config.ts +236 -236
  85. package/src/auth/safe-callback.ts +199 -199
  86. package/src/auth/session-cookie-clear.ts +30 -30
  87. package/src/auth/session-reset-link.ts +159 -159
  88. package/src/auth/session-response-sanitizer.ts +151 -151
  89. package/src/auth/types/auth-types.ts +555 -555
  90. package/src/auth/types/index.ts +7 -7
  91. package/src/auth/unauthenticated-routes.ts +2 -2
  92. package/src/auth/utils/idp-client.ts +364 -364
  93. package/src/auth/utils/index.ts +6 -6
  94. package/src/auth/utils/token-utils.ts +243 -243
  95. package/src/client/AuthContext.tsx +192 -192
  96. package/src/client/better-auth-client.ts +70 -70
  97. package/src/client/fetch-with-auth.ts +47 -47
  98. package/src/client/fetchWithSession.ts +21 -21
  99. package/src/client/index.ts +13 -13
  100. package/src/client/useAnonSession.ts +131 -131
  101. package/src/components/SessionSync.tsx +138 -138
  102. package/src/components/SignalRHealthCheck.tsx +131 -131
  103. package/src/components/account/MobileNavDrawer.tsx +305 -305
  104. package/src/components/account/UserAvatarMenu.tsx +277 -277
  105. package/src/components/account/index.ts +13 -13
  106. package/src/components/admin/AlertSettingsTab.tsx +728 -728
  107. package/src/components/admin/AnalyticsTab.tsx +703 -703
  108. package/src/components/admin/DataBrowserTab.tsx +508 -508
  109. package/src/components/admin/LoggingSettingsTab.tsx +665 -665
  110. package/src/components/admin/SessionsTab.tsx +421 -421
  111. package/src/components/admin/StatsTab.tsx +379 -379
  112. package/src/components/admin/VibeAdminContext.tsx +87 -87
  113. package/src/components/admin/VibeAdminLayout.tsx +187 -187
  114. package/src/components/admin/index.ts +59 -59
  115. package/src/components/auth/CredentialSignInForm.tsx +240 -240
  116. package/src/components/auth/FederatedAuthSection.tsx +129 -129
  117. package/src/components/auth/ModeAwareLoginPage.tsx +146 -146
  118. package/src/components/auth/ModeAwareSignupPage.tsx +200 -200
  119. package/src/components/auth/PasswordResetBridge.tsx +30 -30
  120. package/src/components/auth/TraditionalAuthSection.tsx +103 -103
  121. package/src/components/recovery/CompleteStep.tsx +36 -36
  122. package/src/components/recovery/InitiateRecoveryStep.tsx +68 -68
  123. package/src/components/recovery/RequestedStep.tsx +30 -30
  124. package/src/components/recovery/SelectMethodStep.tsx +73 -73
  125. package/src/components/recovery/SetPasswordStep.tsx +118 -118
  126. package/src/components/recovery/VerifyCodeStep.tsx +90 -90
  127. package/src/components/reserved/ReservedRecoveryWarning.tsx +160 -160
  128. package/src/components/reserved/ReservedStatusBox.tsx +118 -118
  129. package/src/components/ui/BetaBadge.tsx +58 -58
  130. package/src/components/ui/Footer.tsx +93 -93
  131. package/src/config/env.ts +55 -55
  132. package/src/config/logger.ts +62 -62
  133. package/src/config/logging-config.ts +82 -82
  134. package/src/config/unauthenticated-routes.ts +19 -19
  135. package/src/config/vibe-log-transport.ts +264 -264
  136. package/src/edge/internal-api-url.ts +65 -65
  137. package/src/edge/middleware.ts +42 -42
  138. package/src/hooks/useAuth.ts +117 -117
  139. package/src/hooks/useAuthSettings.ts +109 -109
  140. package/src/hooks/useAvailableProviders.ts +143 -143
  141. package/src/hooks/usePasswordValidation.ts +127 -127
  142. package/src/hooks/useProfile.ts +82 -82
  143. package/src/hooks/usePublicAuthSettings.ts +171 -171
  144. package/src/hooks/useSessionExpiration.ts +101 -101
  145. package/src/hooks/useViabilitySession.ts +337 -337
  146. package/src/index.ts +64 -64
  147. package/src/lib/anon-session.ts +213 -213
  148. package/src/lib/api-handler.ts +643 -643
  149. package/src/lib/app-slug.ts +228 -228
  150. package/src/lib/authorize-resume.ts +172 -172
  151. package/src/lib/bearer-fetch.ts +31 -31
  152. package/src/lib/client-key.ts +88 -88
  153. package/src/lib/code-step-copy.ts +83 -83
  154. package/src/lib/credential-sign-in-client.ts +101 -101
  155. package/src/lib/demo-mode.ts +18 -18
  156. package/src/lib/device-id.ts +67 -67
  157. package/src/lib/ensure-fresh-access-token.ts +509 -509
  158. package/src/lib/geolocation.ts +265 -265
  159. package/src/lib/idp-client-config.ts +1005 -1005
  160. package/src/lib/idp-fetch.ts +169 -169
  161. package/src/lib/idp-url-guard.ts +37 -37
  162. package/src/lib/internal-api.ts +171 -171
  163. package/src/lib/jwt-decode-client.ts +45 -45
  164. package/src/lib/jwt-decode.ts +82 -82
  165. package/src/lib/lock-window.ts +49 -49
  166. package/src/lib/login-error-message.ts +41 -41
  167. package/src/lib/never-in-response.ts +64 -64
  168. package/src/lib/nextauth-secret.ts +168 -168
  169. package/src/lib/onboarding-proxy.ts +57 -57
  170. package/src/lib/password-rules.ts +50 -50
  171. package/src/lib/rate-limit-service.ts +9 -9
  172. package/src/lib/redis.ts +105 -105
  173. package/src/lib/refresh-token-validator.ts +64 -64
  174. package/src/lib/roles.ts +177 -177
  175. package/src/lib/safe-error-response.ts +149 -149
  176. package/src/lib/secret-validation.ts +8 -8
  177. package/src/lib/session-cookie-shape.ts +185 -185
  178. package/src/lib/session-store.ts +1092 -1092
  179. package/src/lib/session.ts +34 -34
  180. package/src/lib/single-flight.ts +64 -64
  181. package/src/lib/site-logger.ts +245 -245
  182. package/src/lib/standardized-client-api.ts +901 -901
  183. package/src/lib/startup-init.ts +276 -276
  184. package/src/lib/test-aware-get-token.ts +41 -41
  185. package/src/lib/token-expiry.ts +40 -40
  186. package/src/lib/token-lifecycle.ts +546 -546
  187. package/src/lib/token-log-id.ts +69 -69
  188. package/src/lib/twofa-rejection.ts +91 -91
  189. package/src/lib/types/api-responses.ts +336 -336
  190. package/src/lib/user-agent-parser.ts +252 -252
  191. package/src/logging/api/admin-analytics.ts +51 -51
  192. package/src/logging/api/audit-log.ts +53 -53
  193. package/src/logging/components/AdminAnalyticsLayout.tsx +49 -49
  194. package/src/logging/components/AuditLogViewer.tsx +125 -125
  195. package/src/logging/components/ErrorMetricsCard.tsx +98 -98
  196. package/src/logging/components/HealthMetricsCard.tsx +70 -70
  197. package/src/logging/hooks/useAdminAnalytics.ts +22 -22
  198. package/src/logging/hooks/useAuditLog.ts +24 -24
  199. package/src/logging/hooks/useErrorMetrics.ts +40 -40
  200. package/src/logging/hooks/useHealthMetrics.ts +44 -44
  201. package/src/logging/index.ts +18 -18
  202. package/src/logging/types/analytics.ts +81 -81
  203. package/src/logging/types/audit.ts +31 -31
  204. package/src/logging/types/index.ts +3 -3
  205. package/src/middleware/create-middleware.ts +1141 -1141
  206. package/src/middleware/rbac-check.ts +279 -279
  207. package/src/middleware/twofa-presets.ts +224 -224
  208. package/src/models/DecodedAccessToken.ts +16 -16
  209. package/src/models/SessionModel.ts +331 -331
  210. package/src/pages/admin-login/page.tsx +111 -111
  211. package/src/pages/admin-page-permissions/PagePermissionsAdminPage.tsx +527 -527
  212. package/src/pages/admin-page-permissions/index.ts +7 -7
  213. package/src/pages/admin-roles/RolesAdminPage.tsx +533 -533
  214. package/src/pages/admin-roles/index.ts +9 -9
  215. package/src/pages/admin-roles/modals.tsx +469 -469
  216. package/src/pages/client-admin/ClientSiteAdminPage.tsx +382 -382
  217. package/src/pages/client-admin/index.ts +33 -33
  218. package/src/pages/coming-soon/page.tsx +83 -83
  219. package/src/pages/login/page.tsx +338 -338
  220. package/src/pages/onboarding/index.ts +11 -11
  221. package/src/pages/onboarding/page.tsx +212 -212
  222. package/src/pages/profile/EnhancedProfilePage.tsx +514 -514
  223. package/src/pages/profile/index.ts +9 -9
  224. package/src/pages/profile/page.tsx +166 -166
  225. package/src/pages/recovery/page.tsx +267 -267
  226. package/src/pages/roles/MyRolesPage.tsx +211 -211
  227. package/src/pages/roles/components.tsx +294 -294
  228. package/src/pages/roles/index.ts +17 -17
  229. package/src/pages/security/EnhancedSecurityPage.tsx +660 -660
  230. package/src/pages/security/index.ts +12 -12
  231. package/src/pages/security/page.tsx +507 -507
  232. package/src/pages/service-unavailable/page.tsx +63 -63
  233. package/src/pages/settings/EnhancedSettingsPage.tsx +642 -642
  234. package/src/pages/settings/index.ts +9 -9
  235. package/src/pages/settings/page.tsx +47 -47
  236. package/src/pages/showcase/ShowcasePage.tsx +532 -532
  237. package/src/pages/showcase/index.ts +13 -13
  238. package/src/pages/test-env/EmergencyLogoutPage.tsx +192 -192
  239. package/src/pages/test-env/JwtInspectPage.tsx +449 -449
  240. package/src/pages/test-env/RefreshTokenPage.tsx +178 -178
  241. package/src/pages/test-env/TestEnvPage.tsx +130 -130
  242. package/src/pages/test-env/guarded.tsx +81 -81
  243. package/src/pages/test-env/index.ts +77 -77
  244. package/src/pages/test-env/redact-credentials.ts +96 -96
  245. package/src/pages/verify-code/page.tsx +746 -746
  246. package/src/routes/account/index.ts +31 -31
  247. package/src/routes/account/masked-info.ts +36 -36
  248. package/src/routes/account/send-code.ts +39 -39
  249. package/src/routes/account/update-phone.ts +13 -13
  250. package/src/routes/account/verify-email.ts +40 -40
  251. package/src/routes/account/verify-sms.ts +40 -40
  252. package/src/routes/auth/credential-login-email-code.ts +6 -6
  253. package/src/routes/auth/credential-login.ts +6 -6
  254. package/src/routes/auth/index.ts +22 -22
  255. package/src/routes/auth/logout.ts +111 -111
  256. package/src/routes/auth/nextauth.ts +45 -45
  257. package/src/routes/auth/passkey-signin.ts +13 -13
  258. package/src/routes/auth/refresh.ts +77 -77
  259. package/src/routes/auth/session-reset.ts +37 -37
  260. package/src/routes/auth/session.ts +261 -261
  261. package/src/routes/auth/settings.ts +181 -181
  262. package/src/routes/auth/viability.ts +519 -519
  263. package/src/routes/index.ts +17 -17
  264. package/src/routes/mfa/backup-code-verify.ts +1 -1
  265. package/src/routes/mfa/backup-codes.ts +10 -10
  266. package/src/routes/mfa/methods.ts +22 -22
  267. package/src/routes/mfa/totp-confirm.ts +10 -10
  268. package/src/routes/mfa/totp-enroll.ts +10 -10
  269. package/src/routes/mfa/totp-verify.ts +14 -14
  270. package/src/routes/onboarding/index.ts +15 -15
  271. package/src/routes/onboarding/send-email-code.ts +2 -2
  272. package/src/routes/onboarding/set-password.ts +2 -2
  273. package/src/routes/onboarding/verify-code.ts +2 -2
  274. package/src/routes/onboarding/verify-welcome-email.ts +2 -2
  275. package/src/routes/passkeys/list.ts +10 -10
  276. package/src/routes/passkeys/manage.ts +23 -23
  277. package/src/routes/passkeys/register-options.ts +10 -10
  278. package/src/routes/passkeys/register-verify.ts +10 -10
  279. package/src/routes/session/index.ts +7 -7
  280. package/src/routes/session/refresh-viability.ts +17 -17
  281. package/src/server/auth-guard.ts +203 -203
  282. package/src/server/auth.ts +486 -486
  283. package/src/server/decode-session.ts +309 -309
  284. package/src/server/slim-middleware.ts +117 -117
  285. package/src/server/verified-session-token.ts +103 -103
  286. package/src/server/with-auth.ts +93 -93
  287. package/src/services/signalrActivityService.ts +258 -258
  288. package/src/stores/authStore.ts +1900 -1900
  289. package/src/templates/instrumentation.ts +60 -60
  290. package/src/theme/ThemeProvider.tsx +39 -39
  291. package/src/theme/default.ts +33 -33
  292. package/src/theme/index.ts +31 -31
  293. package/src/theme/types.ts +69 -69
  294. package/src/theme/useTheme.ts +57 -57
  295. package/src/theme/utils.ts +40 -40
  296. package/src/types/api.ts +12 -12
  297. package/src/types/auth.d.ts +23 -23
  298. package/src/types/auth.ts +48 -48
  299. package/src/types/logging.ts +11 -11
  300. package/src/types/recovery.ts +54 -54
  301. package/src/utils/api.ts +401 -401
  302. package/src/utils/circuitBreaker.ts +40 -40
  303. package/src/utils/error-message.ts +108 -108
  304. package/src/utils/layout/reservedSpace.ts +124 -124
  305. package/src/utils/logout.ts +30 -30
  306. package/src/vibe/client.ts +878 -877
  307. package/src/vibe/enterprise-auth.ts +208 -208
  308. package/src/vibe/errors.ts +209 -209
  309. package/src/vibe/filters.ts +52 -0
  310. package/src/vibe/generic.ts +340 -339
  311. package/src/vibe/hooks/index.ts +367 -367
  312. package/src/vibe/index.ts +133 -133
  313. package/src/vibe/sessions.ts +925 -899
  314. package/src/vibe/types.ts +577 -577
@@ -1,660 +1,660 @@
1
- /**
2
- * Enhanced Security Page for @payez/next-mvp
3
- *
4
- * Implements BAPert's Member Self-Service spec with:
5
- * - Password section with change form
6
- * - Two-factor authentication management
7
- * - Connected OAuth accounts
8
- * - Active sessions list
9
- * - Recent activity log
10
- * - Danger zone (data export, account deletion)
11
- *
12
- * @see docs/specs/MEMBER_SELF_SERVICE_SPEC.md
13
- *
14
- * @deprecated RETIRED (BAPert ruling, card 221074, 2026-08-18). The canonical,
15
- * maintained copy is graft-local:
16
- * idp_admin_ui_graft/src/app/account/security/EnhancedSecurityPage.tsx.
17
- * What stage serves is what was scored against Clerk; this package copy was
18
- * imported by nothing in the graft and receives NO further fixes. Do not
19
- * import it into new work.
20
- */
21
-
22
- 'use client';
23
-
24
- import React, { useState, useEffect, useCallback } from 'react';
25
- import { useProfile } from '../../hooks/useProfile';
26
- import { usePasswordValidation } from '../../hooks/usePasswordValidation';
27
- import { useLayout, useColors } from '../../theme/useTheme';
28
-
29
- // Types matching BAPert's spec
30
- interface SecurityData {
31
- password?: {
32
- last_changed?: string;
33
- expires_at?: string;
34
- days_until_expiry?: number;
35
- requires_change?: boolean;
36
- };
37
- two_factor?: {
38
- enabled: boolean;
39
- method?: 'sms' | 'email' | 'authenticator';
40
- method_display?: string;
41
- last_updated?: string;
42
- requires_reenrollment?: boolean;
43
- backup_codes_remaining?: number;
44
- };
45
- connected_accounts?: Array<{
46
- provider: string;
47
- provider_key: string;
48
- email?: string;
49
- connected_at?: string;
50
- can_disconnect?: boolean;
51
- }>;
52
- active_sessions?: Array<{
53
- session_id: string;
54
- device_type?: 'desktop' | 'mobile' | 'tablet';
55
- device_name?: string;
56
- ip_address?: string;
57
- location?: string;
58
- created_at?: string;
59
- last_active_at?: string;
60
- is_current?: boolean;
61
- }>;
62
- recent_activity?: Array<{
63
- event_type: string;
64
- description: string;
65
- device?: string;
66
- timestamp: string;
67
- success: boolean;
68
- }>;
69
- }
70
-
71
- interface PasswordData {
72
- current_password: string;
73
- new_password: string;
74
- confirm_password: string;
75
- }
76
-
77
- // Password Strength Meter Component
78
- function PasswordStrengthMeter({ score, failedRequirements, tip, isDark }: {
79
- score: number;
80
- failedRequirements: string[];
81
- tip?: string;
82
- isDark: boolean;
83
- }) {
84
- const getColor = (s: number) => {
85
- if (s >= 4) return 'bg-green-500';
86
- if (s >= 3) return 'bg-yellow-500';
87
- if (s >= 2) return 'bg-orange-500';
88
- return 'bg-red-500';
89
- };
90
- const getLabel = (s: number) => {
91
- if (s >= 4) return 'Strong';
92
- if (s >= 3) return 'Good';
93
- if (s >= 2) return 'Fair';
94
- if (s >= 1) return 'Weak';
95
- return 'Very Weak';
96
- };
97
- const mutedText = isDark ? 'text-slate-400' : 'text-gray-500';
98
- const barBg = isDark ? 'bg-slate-600' : 'bg-gray-200';
99
-
100
- return (
101
- <div className="space-y-2">
102
- <div className="flex items-center gap-2">
103
- <div className={`flex-1 h-2 rounded-full overflow-hidden ${barBg}`}>
104
- <div className={`h-full transition-all duration-300 ${getColor(score)}`} style={{ width: `${Math.min(score * 20, 100)}%` }} />
105
- </div>
106
- <span className={`text-xs w-16 ${mutedText}`}>{getLabel(score)}</span>
107
- </div>
108
- {failedRequirements.length > 0 && (
109
- <ul className={`text-xs space-y-1 ${mutedText}`}>
110
- {failedRequirements.map((req, i) => (
111
- <li key={i} className="flex items-center gap-1"><span className="text-red-400">x</span> {req}</li>
112
- ))}
113
- </ul>
114
- )}
115
- {tip && <p className="text-xs text-blue-400">{tip}</p>}
116
- </div>
117
- );
118
- }
119
-
120
- // Policy Checklist Component
121
- function PolicyChecklist({ policy, password, isDark }: { policy: any; password: string; isDark: boolean }) {
122
- const checks = React.useMemo(() => {
123
- const list: { label: string; ok: boolean }[] = [];
124
- const minLen = policy?.min_length || 8;
125
- list.push({ label: `At least ${minLen} characters`, ok: (password?.length || 0) >= minLen });
126
- if (policy?.require_uppercase) list.push({ label: 'One uppercase letter', ok: /[A-Z]/.test(password || '') });
127
- if (policy?.require_lowercase) list.push({ label: 'One lowercase letter', ok: /[a-z]/.test(password || '') });
128
- if (policy?.require_digit) list.push({ label: 'One digit', ok: /\d/.test(password || '') });
129
- if (policy?.require_special) list.push({ label: 'One special character', ok: /[^A-Za-z0-9]/.test(password || '') });
130
- return list;
131
- }, [policy, password]);
132
-
133
- const mutedText = isDark ? 'text-slate-400' : 'text-gray-500';
134
- return (
135
- <div className="space-y-1 text-xs">
136
- {checks.map((c, i) => (
137
- <div key={i} className="flex items-center gap-2">
138
- {c.ok ? <span className="text-green-400">v</span> : <span className={mutedText}>o</span>}
139
- <span className={c.ok ? 'text-green-400' : mutedText}>{c.label}</span>
140
- </div>
141
- ))}
142
- </div>
143
- );
144
- }
145
-
146
- // Section Card Component
147
- function SecuritySection({ title, description, children, isDark }: {
148
- title: string;
149
- description?: string;
150
- children: React.ReactNode;
151
- isDark: boolean;
152
- }) {
153
- const cardBg = isDark ? 'bg-slate-800' : 'bg-white';
154
- const borderColor = isDark ? 'border-slate-700' : 'border-gray-200';
155
- const textPrimary = isDark ? 'text-white' : 'text-gray-900';
156
- const textMuted = isDark ? 'text-slate-400' : 'text-gray-500';
157
-
158
- return (
159
- <div className={`rounded-lg border ${cardBg} ${borderColor}`}>
160
- <div className={`px-6 py-4 border-b ${borderColor}`}>
161
- <h2 className={`text-lg font-semibold ${textPrimary}`}>{title}</h2>
162
- {description && <p className={`text-sm mt-1 ${textMuted}`}>{description}</p>}
163
- </div>
164
- <div className="px-6 py-4">{children}</div>
165
- </div>
166
- );
167
- }
168
-
169
- // Status Badge Component
170
- function StatusBadge({ enabled, label, isDark }: { enabled: boolean; label?: string; isDark: boolean }) {
171
- const bgClass = enabled
172
- ? 'bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400'
173
- : 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400';
174
- return (
175
- <span className={`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${bgClass}`}>
176
- {label || (enabled ? 'Enabled' : 'Not Active')}
177
- </span>
178
- );
179
- }
180
-
181
- function formatDate(dateString?: string): string {
182
- if (!dateString) return '';
183
- try {
184
- return new Date(dateString).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
185
- } catch { return dateString; }
186
- }
187
-
188
- function formatRelativeTime(dateString?: string): string {
189
- if (!dateString) return '';
190
- try {
191
- const date = new Date(dateString);
192
- const now = new Date();
193
- const diffMs = now.getTime() - date.getTime();
194
- const diffMins = Math.floor(diffMs / 60000);
195
- const diffHours = Math.floor(diffMs / 3600000);
196
- const diffDays = Math.floor(diffMs / 86400000);
197
- if (diffMins < 1) return 'Just now';
198
- if (diffMins < 60) return `${diffMins}m ago`;
199
- if (diffHours < 24) return `${diffHours}h ago`;
200
- if (diffDays < 7) return `${diffDays}d ago`;
201
- return formatDate(dateString);
202
- } catch { return dateString; }
203
- }
204
-
205
- export interface EnhancedSecurityPageProps {
206
- /**
207
- * 152745. Where "Enable 2FA" navigates to start enrollment. Deliberately a
208
- * PROP, not a hardcoded route: this component ships in a shared package
209
- * consumed by apps whose enrollment routes differ (idp_admin_ui_graft has
210
- * one at /user-authentication/multi-factor; idealresume — per QAPert's
211
- * 170047 gate — has NONE at all). Hardcoding either app's route into the
212
- * package would be wrong for the other, and would silently reproduce the
213
- * exact "advertises 2FA, nothing reachable" defect this card exists to
214
- * fix. Undefined -> the button renders honestly disabled (see below),
215
- * never a fake-live control pointing nowhere.
216
- */
217
- mfaEnrollHref?: string;
218
- /**
219
- * 152745. Called when "Disable 2FA" is clicked. Left to the consumer for
220
- * the same reason as mfaEnrollHref: disabling 2FA is a real, consequential
221
- * write (DELETE /api/Account/mfa/methods/{id} per cluster card 170059) and
222
- * this package has no opinion on which method id, confirmation flow, or
223
- * step-up policy a given app requires. Undefined -> honestly disabled.
224
- */
225
- onDisable2FA?: () => Promise<void> | void;
226
- }
227
-
228
- /**
229
- * @deprecated RETIRED (BAPert ruling, card 221074, 2026-08-18). Canonical copy:
230
- * idp_admin_ui_graft/src/app/account/security/EnhancedSecurityPage.tsx.
231
- * This copy receives NO further fixes. Do not import.
232
- */
233
- export default function EnhancedSecurityPage({ mfaEnrollHref, onDisable2FA }: EnhancedSecurityPageProps = {}) {
234
- const { data: profileData, isLoading: isProfileLoading } = useProfile();
235
- const layout = useLayout();
236
- const colors = useColors();
237
- const [disabling2FA, setDisabling2FA] = useState(false);
238
- const [disable2FAError, setDisable2FAError] = useState('');
239
-
240
- const handleDisable2FA = async () => {
241
- if (!onDisable2FA || disabling2FA) return;
242
- setDisable2FAError('');
243
- try {
244
- setDisabling2FA(true);
245
- await onDisable2FA();
246
- } catch (err: any) {
247
- setDisable2FAError(err?.message || 'Failed to disable two-factor authentication');
248
- } finally {
249
- setDisabling2FA(false);
250
- }
251
- };
252
-
253
- // Re-auth action types (moved for scope)
254
- type ReAuthAction = 'enable_2fa' | 'disable_2fa' | 'export_data' | 'delete_account' | null;
255
-
256
- // Security data state (would come from API in production)
257
- const [securityData, setSecurityData] = useState<SecurityData | null>(null);
258
- const [loadingSecurityData, setLoadingSecurityData] = useState(true);
259
-
260
- // Determine dark mode
261
- const isDark = colors?.background?.includes('slate-9') ||
262
- colors?.background?.includes('gray-9') ||
263
- colors?.card?.includes('slate-8');
264
-
265
- // Password form state
266
- const [formData, setFormData] = useState<PasswordData>({
267
- current_password: '',
268
- new_password: '',
269
- confirm_password: '',
270
- });
271
- const [showPasswords, setShowPasswords] = useState({ current: false, new: false, confirm: false });
272
-
273
- // Re-authentication modal state (Security Addendum)
274
- const [reAuthModal, setReAuthModal] = useState<{
275
- isOpen: boolean;
276
- action: ReAuthAction;
277
- }>({ isOpen: false, action: null });
278
- const [submitting, setSubmitting] = useState(false);
279
- const [error, setError] = useState('');
280
- const [success, setSuccess] = useState('');
281
-
282
- // Password validation
283
- const { setPassword: validateNewPassword, isValid: newPasswordIsValid, score: newPasswordScore, failedRequirements, tip, policy } = usePasswordValidation({ debounceMs: 250 });
284
-
285
- useEffect(() => { validateNewPassword(formData.new_password); }, [formData.new_password, validateNewPassword]);
286
-
287
- // Fetch security data
288
- const fetchSecurityData = useCallback(async () => {
289
- try {
290
- setLoadingSecurityData(true);
291
- const res = await fetch('/api/account/security');
292
- if (res.ok) {
293
- const data = await res.json();
294
- setSecurityData(data);
295
- }
296
- } catch (err) {
297
- // Security data fetch is optional - page still works without it
298
- } finally {
299
- setLoadingSecurityData(false);
300
- }
301
- }, []);
302
-
303
- useEffect(() => {
304
- if (profileData) fetchSecurityData();
305
- }, [profileData, fetchSecurityData]);
306
-
307
- const passwordsMatch = formData.confirm_password.length > 0 && formData.new_password === formData.confirm_password;
308
- const canSubmit = !submitting && newPasswordIsValid && passwordsMatch && formData.current_password.length > 0;
309
-
310
- const handlePasswordSubmit = async (e: React.FormEvent) => {
311
- e.preventDefault();
312
- setError('');
313
- setSuccess('');
314
-
315
- if (!canSubmit) return;
316
-
317
- try {
318
- setSubmitting(true);
319
- const response = await fetch('/api/account/change-password', {
320
- method: 'POST',
321
- headers: { 'Content-Type': 'application/json' },
322
- body: JSON.stringify(formData),
323
- });
324
-
325
- const result = await response.json();
326
- if (!response.ok || !result.success) {
327
- let errorMsg = result.message || 'Failed to change password';
328
- if (result.details?.value?.[0]?.message) errorMsg = result.details.value[0].message;
329
- setError(errorMsg);
330
- return;
331
- }
332
-
333
- setSuccess(result.message || 'Password changed successfully');
334
- setFormData({ current_password: '', new_password: '', confirm_password: '' });
335
- } catch (err: any) {
336
- setError(err.message || 'Failed to change password');
337
- } finally {
338
- setSubmitting(false);
339
- }
340
- };
341
-
342
- // Theme classes
343
- const bgClass = isDark ? 'bg-slate-900' : 'bg-gray-50';
344
- const textPrimary = isDark ? 'text-white' : 'text-gray-900';
345
- const textSecondary = isDark ? 'text-slate-300' : 'text-gray-600';
346
- const textMuted = isDark ? 'text-slate-400' : 'text-gray-500';
347
- const cardBg = isDark ? 'bg-slate-800' : 'bg-white';
348
- const borderColor = isDark ? 'border-slate-700' : 'border-gray-200';
349
- const elevatedBg = isDark ? 'bg-slate-700' : 'bg-gray-100';
350
- const inputBg = isDark ? 'bg-slate-800' : 'bg-white';
351
- const inputBorder = isDark ? 'border-slate-600' : 'border-gray-300';
352
- const inputText = isDark ? 'text-white placeholder-slate-400' : 'text-gray-900 placeholder-gray-400';
353
-
354
- // Loading state
355
- if (isProfileLoading) {
356
- return (
357
- <div className={`min-h-screen ${bgClass} flex items-center justify-center`}>
358
- <div className="flex flex-col items-center space-y-4">
359
- <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500" />
360
- <p className={textMuted}>Loading security settings...</p>
361
- </div>
362
- </div>
363
- );
364
- }
365
-
366
- const twoFactorEnabled = profileData?.two_factor_enabled || securityData?.two_factor?.enabled || false;
367
- const twoFactorMethod = securityData?.two_factor?.method_display || (twoFactorEnabled ? 'SMS' : undefined);
368
-
369
- return (
370
- <div className={`min-h-screen ${bgClass}`}>
371
- <div className={`${layout?.maxWidth || 'max-w-3xl'} mx-auto ${layout?.padding || 'p-6'} space-y-6`}>
372
- {/* Page Header */}
373
- <div>
374
- <h1 className={`text-2xl font-bold ${textPrimary}`}>Security</h1>
375
- <p className={`mt-1 ${textMuted}`}>Manage your account security settings</p>
376
- </div>
377
-
378
- {/* Security Summary */}
379
- <div className={`rounded-lg border ${cardBg} ${borderColor} p-6`}>
380
- <h2 className={`text-lg font-semibold mb-4 ${textPrimary}`}>Security Summary</h2>
381
- <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
382
- <div className={`p-4 rounded-lg ${elevatedBg}`}>
383
- <p className={`text-sm font-medium mb-2 ${textSecondary}`}>2FA Status</p>
384
- <StatusBadge enabled={twoFactorEnabled} isDark={isDark} />
385
- {twoFactorMethod && <p className={`text-xs mt-2 ${textMuted}`}>Method: {twoFactorMethod}</p>}
386
- </div>
387
- <div className={`p-4 rounded-lg ${elevatedBg}`}>
388
- <p className={`text-sm font-medium mb-2 ${textSecondary}`}>Email Status</p>
389
- <StatusBadge enabled={profileData?.email_confirmed || false} label={profileData?.email_confirmed ? 'Verified' : 'Not Verified'} isDark={isDark} />
390
- <p className={`text-xs mt-2 ${textMuted} truncate`}>{profileData?.email}</p>
391
- </div>
392
- <div className={`p-4 rounded-lg ${elevatedBg}`}>
393
- <p className={`text-sm font-medium mb-2 ${textSecondary}`}>Phone Status</p>
394
- <StatusBadge enabled={profileData?.phone_confirmed || false} label={profileData?.phone_confirmed ? 'Verified' : 'Not Verified'} isDark={isDark} />
395
- {profileData?.phone_number && <p className={`text-xs mt-2 ${textMuted}`}>{profileData.phone_number}</p>}
396
- </div>
397
- </div>
398
- </div>
399
-
400
- {/* Password Section */}
401
- <SecuritySection title="Password" description={securityData?.password?.last_changed ? `Last changed ${formatDate(securityData.password.last_changed)}` : undefined} isDark={isDark}>
402
- <form onSubmit={handlePasswordSubmit} className="space-y-4">
403
- <div>
404
- <label className={`block text-sm font-medium mb-2 ${textSecondary}`}>Current Password</label>
405
- <div className="relative">
406
- <input
407
- type={showPasswords.current ? 'text' : 'password'}
408
- value={formData.current_password}
409
- onChange={e => setFormData({ ...formData, current_password: e.target.value })}
410
- className={`w-full px-3 py-2 rounded-md border focus:outline-none focus:ring-2 focus:ring-blue-500 ${inputBg} ${inputBorder} ${inputText}`}
411
- placeholder="Enter current password"
412
- disabled={submitting}
413
- />
414
- <button type="button" onClick={() => setShowPasswords(p => ({ ...p, current: !p.current }))} className={`absolute inset-y-0 right-2 flex items-center ${textMuted}`}>
415
- {showPasswords.current ? 'Hide' : 'Show'}
416
- </button>
417
- </div>
418
- </div>
419
-
420
- <div>
421
- <label className={`block text-sm font-medium mb-2 ${textSecondary}`}>New Password</label>
422
- <div className="relative">
423
- <input
424
- type={showPasswords.new ? 'text' : 'password'}
425
- value={formData.new_password}
426
- onChange={e => setFormData({ ...formData, new_password: e.target.value })}
427
- className={`w-full px-3 py-2 rounded-md border focus:outline-none focus:ring-2 focus:ring-blue-500 ${inputBg} ${inputBorder} ${inputText}`}
428
- placeholder="Enter new password"
429
- disabled={submitting}
430
- />
431
- <button type="button" onClick={() => setShowPasswords(p => ({ ...p, new: !p.new }))} className={`absolute inset-y-0 right-2 flex items-center ${textMuted}`}>
432
- {showPasswords.new ? 'Hide' : 'Show'}
433
- </button>
434
- </div>
435
- {formData.new_password && (
436
- <div className="mt-2">
437
- <PasswordStrengthMeter score={newPasswordScore} failedRequirements={failedRequirements} tip={tip} isDark={isDark} />
438
- </div>
439
- )}
440
- {policy && formData.new_password && (
441
- <div className="mt-3">
442
- <PolicyChecklist policy={policy} password={formData.new_password} isDark={isDark} />
443
- </div>
444
- )}
445
- </div>
446
-
447
- <div>
448
- <label className={`block text-sm font-medium mb-2 ${textSecondary}`}>Confirm New Password</label>
449
- <div className="relative">
450
- <input
451
- type={showPasswords.confirm ? 'text' : 'password'}
452
- value={formData.confirm_password}
453
- onChange={e => setFormData({ ...formData, confirm_password: e.target.value })}
454
- className={`w-full px-3 py-2 rounded-md border focus:outline-none focus:ring-2 focus:ring-blue-500 ${inputBg} ${inputBorder} ${inputText}`}
455
- placeholder="Confirm new password"
456
- disabled={submitting}
457
- />
458
- <button type="button" onClick={() => setShowPasswords(p => ({ ...p, confirm: !p.confirm }))} className={`absolute inset-y-0 right-2 flex items-center ${textMuted}`}>
459
- {showPasswords.confirm ? 'Hide' : 'Show'}
460
- </button>
461
- </div>
462
- {formData.confirm_password && !passwordsMatch && <p className="mt-1 text-xs text-red-400">Passwords do not match</p>}
463
- {formData.confirm_password && passwordsMatch && <p className="mt-1 text-xs text-green-400">Passwords match</p>}
464
- </div>
465
-
466
- {error && <div className="bg-red-900/30 border border-red-600 rounded-lg p-3"><p className="text-red-400 text-sm">{error}</p></div>}
467
- {success && <div className="bg-green-900/30 border border-green-600 rounded-lg p-3"><p className="text-green-400 text-sm">{success}</p></div>}
468
-
469
- <button
470
- type="submit"
471
- disabled={!canSubmit}
472
- className="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed"
473
- >
474
- {submitting ? 'Changing...' : 'Change Password'}
475
- </button>
476
- </form>
477
- </SecuritySection>
478
-
479
- {/* Two-Factor Authentication */}
480
- <SecuritySection title="Two-Factor Authentication" description="Add an extra layer of security to your account" isDark={isDark}>
481
- <div className="space-y-4">
482
- <div className="flex items-center justify-between">
483
- <div>
484
- <p className={`font-medium ${textPrimary}`}>Status</p>
485
- <p className={`text-sm ${textMuted}`}>{twoFactorEnabled ? `Enabled via ${twoFactorMethod || 'SMS'}` : 'Not enabled'}</p>
486
- </div>
487
- <StatusBadge enabled={twoFactorEnabled} isDark={isDark} />
488
- </div>
489
- {twoFactorEnabled ? (
490
- <div className="flex flex-col gap-2">
491
- <div className="flex gap-2">
492
- <button className={`px-3 py-1.5 text-sm rounded border ${isDark ? 'border-slate-600 hover:bg-slate-700' : 'border-gray-300 hover:bg-gray-50'} ${textSecondary}`}>
493
- Change Method
494
- </button>
495
- {/* 152745: was a dead styled button (no onClick/type/href) that
496
- advertised a working control. Disabling a real 2FA method
497
- is consequential (DELETE .../mfa/methods/{id}, cluster
498
- 170059), so this package has no default action — only a
499
- consumer-supplied onDisable2FA makes it live. Unwired, it
500
- renders honestly disabled rather than clickable-looking. */}
501
- <button
502
- type="button"
503
- onClick={handleDisable2FA}
504
- disabled={!onDisable2FA || disabling2FA}
505
- title={!onDisable2FA ? 'Disabling two-factor authentication is not available here' : undefined}
506
- className="px-3 py-1.5 text-sm rounded border border-red-500 text-red-500 hover:bg-red-500/10 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent"
507
- >
508
- {disabling2FA ? 'Disabling...' : 'Disable 2FA'}
509
- </button>
510
- </div>
511
- {disable2FAError && <p className="text-xs text-red-400">{disable2FAError}</p>}
512
- </div>
513
- ) : mfaEnrollHref ? (
514
- // 152745: real navigation to the consumer's own enrollment
515
- // route (a plain <a>, matching "Back to Profile" below — this
516
- // package has no opinion on which router the host app uses).
517
- <a
518
- href={mfaEnrollHref}
519
- className="inline-block px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700"
520
- >
521
- Enable 2FA
522
- </a>
523
- ) : (
524
- // 152745: no enrollment destination configured. This is the
525
- // case QAPert's 170047 gate found live on idealresume.online —
526
- // rendering an active-looking button here would be the exact
527
- // "advertises 2FA, nothing reachable" defect this card exists
528
- // to close, just moved from "no onClick" to "onClick navigates
529
- // to a 404". Honestly disabled instead.
530
- <button
531
- type="button"
532
- disabled
533
- title="Two-factor authentication enrollment is not available here"
534
- className="px-4 py-2 bg-blue-600 text-white rounded-md opacity-40 cursor-not-allowed"
535
- >
536
- Enable 2FA
537
- </button>
538
- )}
539
- {securityData?.two_factor?.backup_codes_remaining !== undefined && (
540
- <div className={`mt-4 p-3 rounded-lg ${elevatedBg}`}>
541
- <p className={`text-sm ${textSecondary}`}>Backup Codes</p>
542
- <p className={textMuted}>You have {securityData.two_factor.backup_codes_remaining} of 10 backup codes remaining</p>
543
- <button className={`mt-2 text-sm ${isDark ? 'text-blue-400' : 'text-blue-600'}`}>View Codes</button>
544
- </div>
545
- )}
546
- </div>
547
- </SecuritySection>
548
-
549
- {/* Connected Accounts */}
550
- <SecuritySection title="Connected Accounts" description="OAuth providers linked to your account" isDark={isDark}>
551
- {securityData?.connected_accounts && securityData.connected_accounts.length > 0 ? (
552
- <div className="space-y-3">
553
- {securityData.connected_accounts.map((account, idx) => (
554
- <div key={idx} className={`flex items-center justify-between p-3 rounded-lg ${elevatedBg}`}>
555
- <div>
556
- <p className={`font-medium ${textPrimary}`}>{account.provider}</p>
557
- {account.email && <p className={`text-sm ${textMuted}`}>{account.email}</p>}
558
- {account.connected_at && <p className={`text-xs ${textMuted}`}>Connected {formatDate(account.connected_at)}</p>}
559
- </div>
560
- {account.can_disconnect && (
561
- <button className="text-sm text-red-500 hover:text-red-400">Disconnect</button>
562
- )}
563
- </div>
564
- ))}
565
- </div>
566
- ) : (
567
- <p className={textMuted}>No connected accounts</p>
568
- )}
569
- <button className={`mt-4 text-sm ${isDark ? 'text-blue-400' : 'text-blue-600'}`}>
570
- Connect Another Account
571
- </button>
572
- </SecuritySection>
573
-
574
- {/* Active Sessions */}
575
- <SecuritySection title="Active Sessions" description="Devices currently logged into your account" isDark={isDark}>
576
- {securityData?.active_sessions && securityData.active_sessions.length > 0 ? (
577
- <div className="space-y-3">
578
- {securityData.active_sessions.map((session, idx) => (
579
- <div key={idx} className={`flex items-center justify-between p-3 rounded-lg ${elevatedBg}`}>
580
- <div>
581
- <div className="flex items-center gap-2">
582
- <p className={`font-medium ${textPrimary}`}>{session.device_name || 'Unknown Device'}</p>
583
- {session.is_current && <span className="px-2 py-0.5 rounded text-xs bg-blue-500 text-white">This Device</span>}
584
- </div>
585
- <p className={`text-sm ${textMuted}`}>{session.location || session.ip_address}</p>
586
- <p className={`text-xs ${textMuted}`}>{session.is_current ? 'Active now' : `Last active ${formatRelativeTime(session.last_active_at)}`}</p>
587
- </div>
588
- {!session.is_current && (
589
- <button className="text-sm text-red-500 hover:text-red-400">Revoke</button>
590
- )}
591
- </div>
592
- ))}
593
- </div>
594
- ) : (
595
- <p className={textMuted}>Session information not available</p>
596
- )}
597
- <button className="mt-4 text-sm text-red-500 hover:text-red-400">
598
- Sign Out All Other Devices
599
- </button>
600
- </SecuritySection>
601
-
602
- {/* Recent Activity */}
603
- <SecuritySection title="Recent Activity" description="Security events on your account" isDark={isDark}>
604
- {securityData?.recent_activity && securityData.recent_activity.length > 0 ? (
605
- <div className="space-y-2">
606
- {securityData.recent_activity.slice(0, 5).map((activity, idx) => (
607
- <div key={idx} className={`flex items-center justify-between py-2 border-b last:border-b-0 ${borderColor}`}>
608
- <div className="flex items-center gap-2">
609
- <span className={activity.success ? 'text-green-400' : 'text-red-400'}>{activity.success ? 'v' : 'x'}</span>
610
- <div>
611
- <p className={`text-sm ${textPrimary}`}>{activity.description}</p>
612
- {activity.device && <p className={`text-xs ${textMuted}`}>{activity.device}</p>}
613
- </div>
614
- </div>
615
- <p className={`text-xs ${textMuted}`}>{formatRelativeTime(activity.timestamp)}</p>
616
- </div>
617
- ))}
618
- </div>
619
- ) : (
620
- <p className={textMuted}>No recent activity</p>
621
- )}
622
- <button className={`mt-4 text-sm ${isDark ? 'text-blue-400' : 'text-blue-600'}`}>
623
- View Full History
624
- </button>
625
- </SecuritySection>
626
-
627
- {/* Danger Zone */}
628
- <SecuritySection title="Danger Zone" description="Irreversible actions" isDark={isDark}>
629
- <div className="space-y-4">
630
- <div className={`flex items-center justify-between p-4 rounded-lg border border-yellow-500/50`}>
631
- <div>
632
- <p className={`font-medium ${textPrimary}`}>Download My Data</p>
633
- <p className={`text-sm ${textMuted}`}>Get a copy of all your personal data</p>
634
- </div>
635
- <button className="px-4 py-2 text-sm rounded border border-yellow-500 text-yellow-500 hover:bg-yellow-500/10">
636
- Request Export
637
- </button>
638
- </div>
639
- <div className={`flex items-center justify-between p-4 rounded-lg border border-red-500/50`}>
640
- <div>
641
- <p className={`font-medium ${textPrimary}`}>Delete Account</p>
642
- <p className={`text-sm ${textMuted}`}>Permanently delete your account and all data</p>
643
- </div>
644
- <button className="px-4 py-2 text-sm rounded border border-red-500 text-red-500 hover:bg-red-500/10">
645
- Delete Account
646
- </button>
647
- </div>
648
- </div>
649
- </SecuritySection>
650
-
651
- {/* Back to Profile link */}
652
- <div className="text-center">
653
- <a href="/account/profile" className={`text-sm hover:underline ${textMuted}`}>
654
- Back to Profile
655
- </a>
656
- </div>
657
- </div>
658
- </div>
659
- );
660
- }
1
+ /**
2
+ * Enhanced Security Page for @payez/next-mvp
3
+ *
4
+ * Implements BAPert's Member Self-Service spec with:
5
+ * - Password section with change form
6
+ * - Two-factor authentication management
7
+ * - Connected OAuth accounts
8
+ * - Active sessions list
9
+ * - Recent activity log
10
+ * - Danger zone (data export, account deletion)
11
+ *
12
+ * @see docs/specs/MEMBER_SELF_SERVICE_SPEC.md
13
+ *
14
+ * @deprecated RETIRED (BAPert ruling, card 221074, 2026-08-18). The canonical,
15
+ * maintained copy is graft-local:
16
+ * idp_admin_ui_graft/src/app/account/security/EnhancedSecurityPage.tsx.
17
+ * What stage serves is what was scored against Clerk; this package copy was
18
+ * imported by nothing in the graft and receives NO further fixes. Do not
19
+ * import it into new work.
20
+ */
21
+
22
+ 'use client';
23
+
24
+ import React, { useState, useEffect, useCallback } from 'react';
25
+ import { useProfile } from '../../hooks/useProfile';
26
+ import { usePasswordValidation } from '../../hooks/usePasswordValidation';
27
+ import { useLayout, useColors } from '../../theme/useTheme';
28
+
29
+ // Types matching BAPert's spec
30
+ interface SecurityData {
31
+ password?: {
32
+ last_changed?: string;
33
+ expires_at?: string;
34
+ days_until_expiry?: number;
35
+ requires_change?: boolean;
36
+ };
37
+ two_factor?: {
38
+ enabled: boolean;
39
+ method?: 'sms' | 'email' | 'authenticator';
40
+ method_display?: string;
41
+ last_updated?: string;
42
+ requires_reenrollment?: boolean;
43
+ backup_codes_remaining?: number;
44
+ };
45
+ connected_accounts?: Array<{
46
+ provider: string;
47
+ provider_key: string;
48
+ email?: string;
49
+ connected_at?: string;
50
+ can_disconnect?: boolean;
51
+ }>;
52
+ active_sessions?: Array<{
53
+ session_id: string;
54
+ device_type?: 'desktop' | 'mobile' | 'tablet';
55
+ device_name?: string;
56
+ ip_address?: string;
57
+ location?: string;
58
+ created_at?: string;
59
+ last_active_at?: string;
60
+ is_current?: boolean;
61
+ }>;
62
+ recent_activity?: Array<{
63
+ event_type: string;
64
+ description: string;
65
+ device?: string;
66
+ timestamp: string;
67
+ success: boolean;
68
+ }>;
69
+ }
70
+
71
+ interface PasswordData {
72
+ current_password: string;
73
+ new_password: string;
74
+ confirm_password: string;
75
+ }
76
+
77
+ // Password Strength Meter Component
78
+ function PasswordStrengthMeter({ score, failedRequirements, tip, isDark }: {
79
+ score: number;
80
+ failedRequirements: string[];
81
+ tip?: string;
82
+ isDark: boolean;
83
+ }) {
84
+ const getColor = (s: number) => {
85
+ if (s >= 4) return 'bg-green-500';
86
+ if (s >= 3) return 'bg-yellow-500';
87
+ if (s >= 2) return 'bg-orange-500';
88
+ return 'bg-red-500';
89
+ };
90
+ const getLabel = (s: number) => {
91
+ if (s >= 4) return 'Strong';
92
+ if (s >= 3) return 'Good';
93
+ if (s >= 2) return 'Fair';
94
+ if (s >= 1) return 'Weak';
95
+ return 'Very Weak';
96
+ };
97
+ const mutedText = isDark ? 'text-slate-400' : 'text-gray-500';
98
+ const barBg = isDark ? 'bg-slate-600' : 'bg-gray-200';
99
+
100
+ return (
101
+ <div className="space-y-2">
102
+ <div className="flex items-center gap-2">
103
+ <div className={`flex-1 h-2 rounded-full overflow-hidden ${barBg}`}>
104
+ <div className={`h-full transition-all duration-300 ${getColor(score)}`} style={{ width: `${Math.min(score * 20, 100)}%` }} />
105
+ </div>
106
+ <span className={`text-xs w-16 ${mutedText}`}>{getLabel(score)}</span>
107
+ </div>
108
+ {failedRequirements.length > 0 && (
109
+ <ul className={`text-xs space-y-1 ${mutedText}`}>
110
+ {failedRequirements.map((req, i) => (
111
+ <li key={i} className="flex items-center gap-1"><span className="text-red-400">x</span> {req}</li>
112
+ ))}
113
+ </ul>
114
+ )}
115
+ {tip && <p className="text-xs text-blue-400">{tip}</p>}
116
+ </div>
117
+ );
118
+ }
119
+
120
+ // Policy Checklist Component
121
+ function PolicyChecklist({ policy, password, isDark }: { policy: any; password: string; isDark: boolean }) {
122
+ const checks = React.useMemo(() => {
123
+ const list: { label: string; ok: boolean }[] = [];
124
+ const minLen = policy?.min_length || 8;
125
+ list.push({ label: `At least ${minLen} characters`, ok: (password?.length || 0) >= minLen });
126
+ if (policy?.require_uppercase) list.push({ label: 'One uppercase letter', ok: /[A-Z]/.test(password || '') });
127
+ if (policy?.require_lowercase) list.push({ label: 'One lowercase letter', ok: /[a-z]/.test(password || '') });
128
+ if (policy?.require_digit) list.push({ label: 'One digit', ok: /\d/.test(password || '') });
129
+ if (policy?.require_special) list.push({ label: 'One special character', ok: /[^A-Za-z0-9]/.test(password || '') });
130
+ return list;
131
+ }, [policy, password]);
132
+
133
+ const mutedText = isDark ? 'text-slate-400' : 'text-gray-500';
134
+ return (
135
+ <div className="space-y-1 text-xs">
136
+ {checks.map((c, i) => (
137
+ <div key={i} className="flex items-center gap-2">
138
+ {c.ok ? <span className="text-green-400">v</span> : <span className={mutedText}>o</span>}
139
+ <span className={c.ok ? 'text-green-400' : mutedText}>{c.label}</span>
140
+ </div>
141
+ ))}
142
+ </div>
143
+ );
144
+ }
145
+
146
+ // Section Card Component
147
+ function SecuritySection({ title, description, children, isDark }: {
148
+ title: string;
149
+ description?: string;
150
+ children: React.ReactNode;
151
+ isDark: boolean;
152
+ }) {
153
+ const cardBg = isDark ? 'bg-slate-800' : 'bg-white';
154
+ const borderColor = isDark ? 'border-slate-700' : 'border-gray-200';
155
+ const textPrimary = isDark ? 'text-white' : 'text-gray-900';
156
+ const textMuted = isDark ? 'text-slate-400' : 'text-gray-500';
157
+
158
+ return (
159
+ <div className={`rounded-lg border ${cardBg} ${borderColor}`}>
160
+ <div className={`px-6 py-4 border-b ${borderColor}`}>
161
+ <h2 className={`text-lg font-semibold ${textPrimary}`}>{title}</h2>
162
+ {description && <p className={`text-sm mt-1 ${textMuted}`}>{description}</p>}
163
+ </div>
164
+ <div className="px-6 py-4">{children}</div>
165
+ </div>
166
+ );
167
+ }
168
+
169
+ // Status Badge Component
170
+ function StatusBadge({ enabled, label, isDark }: { enabled: boolean; label?: string; isDark: boolean }) {
171
+ const bgClass = enabled
172
+ ? 'bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400'
173
+ : 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400';
174
+ return (
175
+ <span className={`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${bgClass}`}>
176
+ {label || (enabled ? 'Enabled' : 'Not Active')}
177
+ </span>
178
+ );
179
+ }
180
+
181
+ function formatDate(dateString?: string): string {
182
+ if (!dateString) return '';
183
+ try {
184
+ return new Date(dateString).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
185
+ } catch { return dateString; }
186
+ }
187
+
188
+ function formatRelativeTime(dateString?: string): string {
189
+ if (!dateString) return '';
190
+ try {
191
+ const date = new Date(dateString);
192
+ const now = new Date();
193
+ const diffMs = now.getTime() - date.getTime();
194
+ const diffMins = Math.floor(diffMs / 60000);
195
+ const diffHours = Math.floor(diffMs / 3600000);
196
+ const diffDays = Math.floor(diffMs / 86400000);
197
+ if (diffMins < 1) return 'Just now';
198
+ if (diffMins < 60) return `${diffMins}m ago`;
199
+ if (diffHours < 24) return `${diffHours}h ago`;
200
+ if (diffDays < 7) return `${diffDays}d ago`;
201
+ return formatDate(dateString);
202
+ } catch { return dateString; }
203
+ }
204
+
205
+ export interface EnhancedSecurityPageProps {
206
+ /**
207
+ * 152745. Where "Enable 2FA" navigates to start enrollment. Deliberately a
208
+ * PROP, not a hardcoded route: this component ships in a shared package
209
+ * consumed by apps whose enrollment routes differ (idp_admin_ui_graft has
210
+ * one at /user-authentication/multi-factor; idealresume — per QAPert's
211
+ * 170047 gate — has NONE at all). Hardcoding either app's route into the
212
+ * package would be wrong for the other, and would silently reproduce the
213
+ * exact "advertises 2FA, nothing reachable" defect this card exists to
214
+ * fix. Undefined -> the button renders honestly disabled (see below),
215
+ * never a fake-live control pointing nowhere.
216
+ */
217
+ mfaEnrollHref?: string;
218
+ /**
219
+ * 152745. Called when "Disable 2FA" is clicked. Left to the consumer for
220
+ * the same reason as mfaEnrollHref: disabling 2FA is a real, consequential
221
+ * write (DELETE /api/Account/mfa/methods/{id} per cluster card 170059) and
222
+ * this package has no opinion on which method id, confirmation flow, or
223
+ * step-up policy a given app requires. Undefined -> honestly disabled.
224
+ */
225
+ onDisable2FA?: () => Promise<void> | void;
226
+ }
227
+
228
+ /**
229
+ * @deprecated RETIRED (BAPert ruling, card 221074, 2026-08-18). Canonical copy:
230
+ * idp_admin_ui_graft/src/app/account/security/EnhancedSecurityPage.tsx.
231
+ * This copy receives NO further fixes. Do not import.
232
+ */
233
+ export default function EnhancedSecurityPage({ mfaEnrollHref, onDisable2FA }: EnhancedSecurityPageProps = {}) {
234
+ const { data: profileData, isLoading: isProfileLoading } = useProfile();
235
+ const layout = useLayout();
236
+ const colors = useColors();
237
+ const [disabling2FA, setDisabling2FA] = useState(false);
238
+ const [disable2FAError, setDisable2FAError] = useState('');
239
+
240
+ const handleDisable2FA = async () => {
241
+ if (!onDisable2FA || disabling2FA) return;
242
+ setDisable2FAError('');
243
+ try {
244
+ setDisabling2FA(true);
245
+ await onDisable2FA();
246
+ } catch (err: any) {
247
+ setDisable2FAError(err?.message || 'Failed to disable two-factor authentication');
248
+ } finally {
249
+ setDisabling2FA(false);
250
+ }
251
+ };
252
+
253
+ // Re-auth action types (moved for scope)
254
+ type ReAuthAction = 'enable_2fa' | 'disable_2fa' | 'export_data' | 'delete_account' | null;
255
+
256
+ // Security data state (would come from API in production)
257
+ const [securityData, setSecurityData] = useState<SecurityData | null>(null);
258
+ const [loadingSecurityData, setLoadingSecurityData] = useState(true);
259
+
260
+ // Determine dark mode
261
+ const isDark = colors?.background?.includes('slate-9') ||
262
+ colors?.background?.includes('gray-9') ||
263
+ colors?.card?.includes('slate-8');
264
+
265
+ // Password form state
266
+ const [formData, setFormData] = useState<PasswordData>({
267
+ current_password: '',
268
+ new_password: '',
269
+ confirm_password: '',
270
+ });
271
+ const [showPasswords, setShowPasswords] = useState({ current: false, new: false, confirm: false });
272
+
273
+ // Re-authentication modal state (Security Addendum)
274
+ const [reAuthModal, setReAuthModal] = useState<{
275
+ isOpen: boolean;
276
+ action: ReAuthAction;
277
+ }>({ isOpen: false, action: null });
278
+ const [submitting, setSubmitting] = useState(false);
279
+ const [error, setError] = useState('');
280
+ const [success, setSuccess] = useState('');
281
+
282
+ // Password validation
283
+ const { setPassword: validateNewPassword, isValid: newPasswordIsValid, score: newPasswordScore, failedRequirements, tip, policy } = usePasswordValidation({ debounceMs: 250 });
284
+
285
+ useEffect(() => { validateNewPassword(formData.new_password); }, [formData.new_password, validateNewPassword]);
286
+
287
+ // Fetch security data
288
+ const fetchSecurityData = useCallback(async () => {
289
+ try {
290
+ setLoadingSecurityData(true);
291
+ const res = await fetch('/api/account/security');
292
+ if (res.ok) {
293
+ const data = await res.json();
294
+ setSecurityData(data);
295
+ }
296
+ } catch (err) {
297
+ // Security data fetch is optional - page still works without it
298
+ } finally {
299
+ setLoadingSecurityData(false);
300
+ }
301
+ }, []);
302
+
303
+ useEffect(() => {
304
+ if (profileData) fetchSecurityData();
305
+ }, [profileData, fetchSecurityData]);
306
+
307
+ const passwordsMatch = formData.confirm_password.length > 0 && formData.new_password === formData.confirm_password;
308
+ const canSubmit = !submitting && newPasswordIsValid && passwordsMatch && formData.current_password.length > 0;
309
+
310
+ const handlePasswordSubmit = async (e: React.FormEvent) => {
311
+ e.preventDefault();
312
+ setError('');
313
+ setSuccess('');
314
+
315
+ if (!canSubmit) return;
316
+
317
+ try {
318
+ setSubmitting(true);
319
+ const response = await fetch('/api/account/change-password', {
320
+ method: 'POST',
321
+ headers: { 'Content-Type': 'application/json' },
322
+ body: JSON.stringify(formData),
323
+ });
324
+
325
+ const result = await response.json();
326
+ if (!response.ok || !result.success) {
327
+ let errorMsg = result.message || 'Failed to change password';
328
+ if (result.details?.value?.[0]?.message) errorMsg = result.details.value[0].message;
329
+ setError(errorMsg);
330
+ return;
331
+ }
332
+
333
+ setSuccess(result.message || 'Password changed successfully');
334
+ setFormData({ current_password: '', new_password: '', confirm_password: '' });
335
+ } catch (err: any) {
336
+ setError(err.message || 'Failed to change password');
337
+ } finally {
338
+ setSubmitting(false);
339
+ }
340
+ };
341
+
342
+ // Theme classes
343
+ const bgClass = isDark ? 'bg-slate-900' : 'bg-gray-50';
344
+ const textPrimary = isDark ? 'text-white' : 'text-gray-900';
345
+ const textSecondary = isDark ? 'text-slate-300' : 'text-gray-600';
346
+ const textMuted = isDark ? 'text-slate-400' : 'text-gray-500';
347
+ const cardBg = isDark ? 'bg-slate-800' : 'bg-white';
348
+ const borderColor = isDark ? 'border-slate-700' : 'border-gray-200';
349
+ const elevatedBg = isDark ? 'bg-slate-700' : 'bg-gray-100';
350
+ const inputBg = isDark ? 'bg-slate-800' : 'bg-white';
351
+ const inputBorder = isDark ? 'border-slate-600' : 'border-gray-300';
352
+ const inputText = isDark ? 'text-white placeholder-slate-400' : 'text-gray-900 placeholder-gray-400';
353
+
354
+ // Loading state
355
+ if (isProfileLoading) {
356
+ return (
357
+ <div className={`min-h-screen ${bgClass} flex items-center justify-center`}>
358
+ <div className="flex flex-col items-center space-y-4">
359
+ <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500" />
360
+ <p className={textMuted}>Loading security settings...</p>
361
+ </div>
362
+ </div>
363
+ );
364
+ }
365
+
366
+ const twoFactorEnabled = profileData?.two_factor_enabled || securityData?.two_factor?.enabled || false;
367
+ const twoFactorMethod = securityData?.two_factor?.method_display || (twoFactorEnabled ? 'SMS' : undefined);
368
+
369
+ return (
370
+ <div className={`min-h-screen ${bgClass}`}>
371
+ <div className={`${layout?.maxWidth || 'max-w-3xl'} mx-auto ${layout?.padding || 'p-6'} space-y-6`}>
372
+ {/* Page Header */}
373
+ <div>
374
+ <h1 className={`text-2xl font-bold ${textPrimary}`}>Security</h1>
375
+ <p className={`mt-1 ${textMuted}`}>Manage your account security settings</p>
376
+ </div>
377
+
378
+ {/* Security Summary */}
379
+ <div className={`rounded-lg border ${cardBg} ${borderColor} p-6`}>
380
+ <h2 className={`text-lg font-semibold mb-4 ${textPrimary}`}>Security Summary</h2>
381
+ <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
382
+ <div className={`p-4 rounded-lg ${elevatedBg}`}>
383
+ <p className={`text-sm font-medium mb-2 ${textSecondary}`}>2FA Status</p>
384
+ <StatusBadge enabled={twoFactorEnabled} isDark={isDark} />
385
+ {twoFactorMethod && <p className={`text-xs mt-2 ${textMuted}`}>Method: {twoFactorMethod}</p>}
386
+ </div>
387
+ <div className={`p-4 rounded-lg ${elevatedBg}`}>
388
+ <p className={`text-sm font-medium mb-2 ${textSecondary}`}>Email Status</p>
389
+ <StatusBadge enabled={profileData?.email_confirmed || false} label={profileData?.email_confirmed ? 'Verified' : 'Not Verified'} isDark={isDark} />
390
+ <p className={`text-xs mt-2 ${textMuted} truncate`}>{profileData?.email}</p>
391
+ </div>
392
+ <div className={`p-4 rounded-lg ${elevatedBg}`}>
393
+ <p className={`text-sm font-medium mb-2 ${textSecondary}`}>Phone Status</p>
394
+ <StatusBadge enabled={profileData?.phone_confirmed || false} label={profileData?.phone_confirmed ? 'Verified' : 'Not Verified'} isDark={isDark} />
395
+ {profileData?.phone_number && <p className={`text-xs mt-2 ${textMuted}`}>{profileData.phone_number}</p>}
396
+ </div>
397
+ </div>
398
+ </div>
399
+
400
+ {/* Password Section */}
401
+ <SecuritySection title="Password" description={securityData?.password?.last_changed ? `Last changed ${formatDate(securityData.password.last_changed)}` : undefined} isDark={isDark}>
402
+ <form onSubmit={handlePasswordSubmit} className="space-y-4">
403
+ <div>
404
+ <label className={`block text-sm font-medium mb-2 ${textSecondary}`}>Current Password</label>
405
+ <div className="relative">
406
+ <input
407
+ type={showPasswords.current ? 'text' : 'password'}
408
+ value={formData.current_password}
409
+ onChange={e => setFormData({ ...formData, current_password: e.target.value })}
410
+ className={`w-full px-3 py-2 rounded-md border focus:outline-none focus:ring-2 focus:ring-blue-500 ${inputBg} ${inputBorder} ${inputText}`}
411
+ placeholder="Enter current password"
412
+ disabled={submitting}
413
+ />
414
+ <button type="button" onClick={() => setShowPasswords(p => ({ ...p, current: !p.current }))} className={`absolute inset-y-0 right-2 flex items-center ${textMuted}`}>
415
+ {showPasswords.current ? 'Hide' : 'Show'}
416
+ </button>
417
+ </div>
418
+ </div>
419
+
420
+ <div>
421
+ <label className={`block text-sm font-medium mb-2 ${textSecondary}`}>New Password</label>
422
+ <div className="relative">
423
+ <input
424
+ type={showPasswords.new ? 'text' : 'password'}
425
+ value={formData.new_password}
426
+ onChange={e => setFormData({ ...formData, new_password: e.target.value })}
427
+ className={`w-full px-3 py-2 rounded-md border focus:outline-none focus:ring-2 focus:ring-blue-500 ${inputBg} ${inputBorder} ${inputText}`}
428
+ placeholder="Enter new password"
429
+ disabled={submitting}
430
+ />
431
+ <button type="button" onClick={() => setShowPasswords(p => ({ ...p, new: !p.new }))} className={`absolute inset-y-0 right-2 flex items-center ${textMuted}`}>
432
+ {showPasswords.new ? 'Hide' : 'Show'}
433
+ </button>
434
+ </div>
435
+ {formData.new_password && (
436
+ <div className="mt-2">
437
+ <PasswordStrengthMeter score={newPasswordScore} failedRequirements={failedRequirements} tip={tip} isDark={isDark} />
438
+ </div>
439
+ )}
440
+ {policy && formData.new_password && (
441
+ <div className="mt-3">
442
+ <PolicyChecklist policy={policy} password={formData.new_password} isDark={isDark} />
443
+ </div>
444
+ )}
445
+ </div>
446
+
447
+ <div>
448
+ <label className={`block text-sm font-medium mb-2 ${textSecondary}`}>Confirm New Password</label>
449
+ <div className="relative">
450
+ <input
451
+ type={showPasswords.confirm ? 'text' : 'password'}
452
+ value={formData.confirm_password}
453
+ onChange={e => setFormData({ ...formData, confirm_password: e.target.value })}
454
+ className={`w-full px-3 py-2 rounded-md border focus:outline-none focus:ring-2 focus:ring-blue-500 ${inputBg} ${inputBorder} ${inputText}`}
455
+ placeholder="Confirm new password"
456
+ disabled={submitting}
457
+ />
458
+ <button type="button" onClick={() => setShowPasswords(p => ({ ...p, confirm: !p.confirm }))} className={`absolute inset-y-0 right-2 flex items-center ${textMuted}`}>
459
+ {showPasswords.confirm ? 'Hide' : 'Show'}
460
+ </button>
461
+ </div>
462
+ {formData.confirm_password && !passwordsMatch && <p className="mt-1 text-xs text-red-400">Passwords do not match</p>}
463
+ {formData.confirm_password && passwordsMatch && <p className="mt-1 text-xs text-green-400">Passwords match</p>}
464
+ </div>
465
+
466
+ {error && <div className="bg-red-900/30 border border-red-600 rounded-lg p-3"><p className="text-red-400 text-sm">{error}</p></div>}
467
+ {success && <div className="bg-green-900/30 border border-green-600 rounded-lg p-3"><p className="text-green-400 text-sm">{success}</p></div>}
468
+
469
+ <button
470
+ type="submit"
471
+ disabled={!canSubmit}
472
+ className="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed"
473
+ >
474
+ {submitting ? 'Changing...' : 'Change Password'}
475
+ </button>
476
+ </form>
477
+ </SecuritySection>
478
+
479
+ {/* Two-Factor Authentication */}
480
+ <SecuritySection title="Two-Factor Authentication" description="Add an extra layer of security to your account" isDark={isDark}>
481
+ <div className="space-y-4">
482
+ <div className="flex items-center justify-between">
483
+ <div>
484
+ <p className={`font-medium ${textPrimary}`}>Status</p>
485
+ <p className={`text-sm ${textMuted}`}>{twoFactorEnabled ? `Enabled via ${twoFactorMethod || 'SMS'}` : 'Not enabled'}</p>
486
+ </div>
487
+ <StatusBadge enabled={twoFactorEnabled} isDark={isDark} />
488
+ </div>
489
+ {twoFactorEnabled ? (
490
+ <div className="flex flex-col gap-2">
491
+ <div className="flex gap-2">
492
+ <button className={`px-3 py-1.5 text-sm rounded border ${isDark ? 'border-slate-600 hover:bg-slate-700' : 'border-gray-300 hover:bg-gray-50'} ${textSecondary}`}>
493
+ Change Method
494
+ </button>
495
+ {/* 152745: was a dead styled button (no onClick/type/href) that
496
+ advertised a working control. Disabling a real 2FA method
497
+ is consequential (DELETE .../mfa/methods/{id}, cluster
498
+ 170059), so this package has no default action — only a
499
+ consumer-supplied onDisable2FA makes it live. Unwired, it
500
+ renders honestly disabled rather than clickable-looking. */}
501
+ <button
502
+ type="button"
503
+ onClick={handleDisable2FA}
504
+ disabled={!onDisable2FA || disabling2FA}
505
+ title={!onDisable2FA ? 'Disabling two-factor authentication is not available here' : undefined}
506
+ className="px-3 py-1.5 text-sm rounded border border-red-500 text-red-500 hover:bg-red-500/10 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent"
507
+ >
508
+ {disabling2FA ? 'Disabling...' : 'Disable 2FA'}
509
+ </button>
510
+ </div>
511
+ {disable2FAError && <p className="text-xs text-red-400">{disable2FAError}</p>}
512
+ </div>
513
+ ) : mfaEnrollHref ? (
514
+ // 152745: real navigation to the consumer's own enrollment
515
+ // route (a plain <a>, matching "Back to Profile" below — this
516
+ // package has no opinion on which router the host app uses).
517
+ <a
518
+ href={mfaEnrollHref}
519
+ className="inline-block px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700"
520
+ >
521
+ Enable 2FA
522
+ </a>
523
+ ) : (
524
+ // 152745: no enrollment destination configured. This is the
525
+ // case QAPert's 170047 gate found live on idealresume.online —
526
+ // rendering an active-looking button here would be the exact
527
+ // "advertises 2FA, nothing reachable" defect this card exists
528
+ // to close, just moved from "no onClick" to "onClick navigates
529
+ // to a 404". Honestly disabled instead.
530
+ <button
531
+ type="button"
532
+ disabled
533
+ title="Two-factor authentication enrollment is not available here"
534
+ className="px-4 py-2 bg-blue-600 text-white rounded-md opacity-40 cursor-not-allowed"
535
+ >
536
+ Enable 2FA
537
+ </button>
538
+ )}
539
+ {securityData?.two_factor?.backup_codes_remaining !== undefined && (
540
+ <div className={`mt-4 p-3 rounded-lg ${elevatedBg}`}>
541
+ <p className={`text-sm ${textSecondary}`}>Backup Codes</p>
542
+ <p className={textMuted}>You have {securityData.two_factor.backup_codes_remaining} of 10 backup codes remaining</p>
543
+ <button className={`mt-2 text-sm ${isDark ? 'text-blue-400' : 'text-blue-600'}`}>View Codes</button>
544
+ </div>
545
+ )}
546
+ </div>
547
+ </SecuritySection>
548
+
549
+ {/* Connected Accounts */}
550
+ <SecuritySection title="Connected Accounts" description="OAuth providers linked to your account" isDark={isDark}>
551
+ {securityData?.connected_accounts && securityData.connected_accounts.length > 0 ? (
552
+ <div className="space-y-3">
553
+ {securityData.connected_accounts.map((account, idx) => (
554
+ <div key={idx} className={`flex items-center justify-between p-3 rounded-lg ${elevatedBg}`}>
555
+ <div>
556
+ <p className={`font-medium ${textPrimary}`}>{account.provider}</p>
557
+ {account.email && <p className={`text-sm ${textMuted}`}>{account.email}</p>}
558
+ {account.connected_at && <p className={`text-xs ${textMuted}`}>Connected {formatDate(account.connected_at)}</p>}
559
+ </div>
560
+ {account.can_disconnect && (
561
+ <button className="text-sm text-red-500 hover:text-red-400">Disconnect</button>
562
+ )}
563
+ </div>
564
+ ))}
565
+ </div>
566
+ ) : (
567
+ <p className={textMuted}>No connected accounts</p>
568
+ )}
569
+ <button className={`mt-4 text-sm ${isDark ? 'text-blue-400' : 'text-blue-600'}`}>
570
+ Connect Another Account
571
+ </button>
572
+ </SecuritySection>
573
+
574
+ {/* Active Sessions */}
575
+ <SecuritySection title="Active Sessions" description="Devices currently logged into your account" isDark={isDark}>
576
+ {securityData?.active_sessions && securityData.active_sessions.length > 0 ? (
577
+ <div className="space-y-3">
578
+ {securityData.active_sessions.map((session, idx) => (
579
+ <div key={idx} className={`flex items-center justify-between p-3 rounded-lg ${elevatedBg}`}>
580
+ <div>
581
+ <div className="flex items-center gap-2">
582
+ <p className={`font-medium ${textPrimary}`}>{session.device_name || 'Unknown Device'}</p>
583
+ {session.is_current && <span className="px-2 py-0.5 rounded text-xs bg-blue-500 text-white">This Device</span>}
584
+ </div>
585
+ <p className={`text-sm ${textMuted}`}>{session.location || session.ip_address}</p>
586
+ <p className={`text-xs ${textMuted}`}>{session.is_current ? 'Active now' : `Last active ${formatRelativeTime(session.last_active_at)}`}</p>
587
+ </div>
588
+ {!session.is_current && (
589
+ <button className="text-sm text-red-500 hover:text-red-400">Revoke</button>
590
+ )}
591
+ </div>
592
+ ))}
593
+ </div>
594
+ ) : (
595
+ <p className={textMuted}>Session information not available</p>
596
+ )}
597
+ <button className="mt-4 text-sm text-red-500 hover:text-red-400">
598
+ Sign Out All Other Devices
599
+ </button>
600
+ </SecuritySection>
601
+
602
+ {/* Recent Activity */}
603
+ <SecuritySection title="Recent Activity" description="Security events on your account" isDark={isDark}>
604
+ {securityData?.recent_activity && securityData.recent_activity.length > 0 ? (
605
+ <div className="space-y-2">
606
+ {securityData.recent_activity.slice(0, 5).map((activity, idx) => (
607
+ <div key={idx} className={`flex items-center justify-between py-2 border-b last:border-b-0 ${borderColor}`}>
608
+ <div className="flex items-center gap-2">
609
+ <span className={activity.success ? 'text-green-400' : 'text-red-400'}>{activity.success ? 'v' : 'x'}</span>
610
+ <div>
611
+ <p className={`text-sm ${textPrimary}`}>{activity.description}</p>
612
+ {activity.device && <p className={`text-xs ${textMuted}`}>{activity.device}</p>}
613
+ </div>
614
+ </div>
615
+ <p className={`text-xs ${textMuted}`}>{formatRelativeTime(activity.timestamp)}</p>
616
+ </div>
617
+ ))}
618
+ </div>
619
+ ) : (
620
+ <p className={textMuted}>No recent activity</p>
621
+ )}
622
+ <button className={`mt-4 text-sm ${isDark ? 'text-blue-400' : 'text-blue-600'}`}>
623
+ View Full History
624
+ </button>
625
+ </SecuritySection>
626
+
627
+ {/* Danger Zone */}
628
+ <SecuritySection title="Danger Zone" description="Irreversible actions" isDark={isDark}>
629
+ <div className="space-y-4">
630
+ <div className={`flex items-center justify-between p-4 rounded-lg border border-yellow-500/50`}>
631
+ <div>
632
+ <p className={`font-medium ${textPrimary}`}>Download My Data</p>
633
+ <p className={`text-sm ${textMuted}`}>Get a copy of all your personal data</p>
634
+ </div>
635
+ <button className="px-4 py-2 text-sm rounded border border-yellow-500 text-yellow-500 hover:bg-yellow-500/10">
636
+ Request Export
637
+ </button>
638
+ </div>
639
+ <div className={`flex items-center justify-between p-4 rounded-lg border border-red-500/50`}>
640
+ <div>
641
+ <p className={`font-medium ${textPrimary}`}>Delete Account</p>
642
+ <p className={`text-sm ${textMuted}`}>Permanently delete your account and all data</p>
643
+ </div>
644
+ <button className="px-4 py-2 text-sm rounded border border-red-500 text-red-500 hover:bg-red-500/10">
645
+ Delete Account
646
+ </button>
647
+ </div>
648
+ </div>
649
+ </SecuritySection>
650
+
651
+ {/* Back to Profile link */}
652
+ <div className="text-center">
653
+ <a href="/account/profile" className={`text-sm hover:underline ${textMuted}`}>
654
+ Back to Profile
655
+ </a>
656
+ </div>
657
+ </div>
658
+ </div>
659
+ );
660
+ }