@payez/next-mvp 4.8.0 → 4.8.2

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 (301) hide show
  1. package/POST-INSTALL.md +408 -408
  2. package/README.md +859 -859
  3. package/dist/components/account/MobileNavDrawer.js +18 -18
  4. package/dist/components/account/UserAvatarMenu.js +1 -1
  5. package/dist/components/admin/AlertSettingsTab.js +40 -40
  6. package/dist/components/admin/LoggingSettingsTab.js +28 -28
  7. package/dist/lib/session-store.js +21 -21
  8. package/dist/lib/startup-init.js +19 -19
  9. package/dist/middleware/create-middleware.js +6 -5
  10. package/dist/pages/login/page.js +28 -28
  11. package/dist/pages/settings/EnhancedSettingsPage.js +17 -17
  12. package/dist/vibe/sessions.js +28 -3
  13. package/package.json +2 -2
  14. package/scripts/check-publish-eol.mjs +33 -15
  15. package/src/api/auth-handler.ts +550 -550
  16. package/src/api/index.ts +17 -17
  17. package/src/api-handlers/account/change-password.ts +170 -170
  18. package/src/api-handlers/account/masked-info.ts +46 -46
  19. package/src/api-handlers/account/profile.ts +99 -99
  20. package/src/api-handlers/account/recovery/forward.ts +117 -117
  21. package/src/api-handlers/account/recovery/initiate.ts +59 -59
  22. package/src/api-handlers/account/recovery/send-code.ts +21 -21
  23. package/src/api-handlers/account/recovery/verify-code.ts +20 -20
  24. package/src/api-handlers/account/reset-password.ts +87 -87
  25. package/src/api-handlers/account/send-code.ts +70 -70
  26. package/src/api-handlers/account/update-phone.ts +84 -84
  27. package/src/api-handlers/account/validate-password.ts +139 -139
  28. package/src/api-handlers/account/verify-email.ts +134 -134
  29. package/src/api-handlers/account/verify-sms.ts +134 -134
  30. package/src/api-handlers/admin/analytics.ts +452 -452
  31. package/src/api-handlers/admin/audit.ts +232 -232
  32. package/src/api-handlers/admin/index.ts +63 -63
  33. package/src/api-handlers/admin/redis-sessions.ts +259 -259
  34. package/src/api-handlers/admin/sessions.ts +327 -327
  35. package/src/api-handlers/admin/site-logs.ts +388 -388
  36. package/src/api-handlers/admin/stats.ts +260 -260
  37. package/src/api-handlers/admin/users.ts +251 -251
  38. package/src/api-handlers/admin/vibe-data.ts +333 -333
  39. package/src/api-handlers/anon/preferences.ts +123 -123
  40. package/src/api-handlers/auth/credential-login-email-code.ts +92 -92
  41. package/src/api-handlers/auth/credential-login.ts +948 -948
  42. package/src/api-handlers/auth/jwks.ts +31 -31
  43. package/src/api-handlers/auth/login.ts +252 -252
  44. package/src/api-handlers/auth/passkey-signin.ts +116 -116
  45. package/src/api-handlers/auth/refresh.ts +829 -829
  46. package/src/api-handlers/auth/signout.ts +201 -201
  47. package/src/api-handlers/auth/status.ts +23 -23
  48. package/src/api-handlers/auth/update-session.ts +144 -144
  49. package/src/api-handlers/auth/validate.ts +45 -45
  50. package/src/api-handlers/auth/verify-code.ts +116 -116
  51. package/src/api-handlers/mfa/backup-code-verify.ts +170 -170
  52. package/src/api-handlers/mfa/backup-codes.ts +42 -42
  53. package/src/api-handlers/mfa/methods.ts +47 -47
  54. package/src/api-handlers/mfa/totp-confirm.ts +43 -43
  55. package/src/api-handlers/mfa/totp-enroll.ts +43 -43
  56. package/src/api-handlers/mfa/totp-verify.ts +172 -172
  57. package/src/api-handlers/oauth/resume.ts +182 -182
  58. package/src/api-handlers/onboarding/send-email-code.ts +18 -18
  59. package/src/api-handlers/onboarding/set-password.ts +21 -21
  60. package/src/api-handlers/onboarding/verify-code.ts +20 -20
  61. package/src/api-handlers/onboarding/verify-welcome-email.ts +17 -17
  62. package/src/api-handlers/passkeys/list.ts +32 -32
  63. package/src/api-handlers/passkeys/manage.ts +55 -55
  64. package/src/api-handlers/passkeys/register-options.ts +43 -43
  65. package/src/api-handlers/passkeys/register-verify.ts +42 -42
  66. package/src/api-handlers/session/refresh-viability.ts +56 -56
  67. package/src/api-handlers/session/viability.ts +238 -238
  68. package/src/api-handlers/test/force-expire.ts +167 -167
  69. package/src/auth/auth-decision.ts +292 -292
  70. package/src/auth/better-auth.ts +1688 -1688
  71. package/src/auth/idp-oauth.ts +310 -310
  72. package/src/auth/password-reset-bridge.ts +98 -98
  73. package/src/auth/route-config.ts +236 -236
  74. package/src/auth/safe-callback.ts +199 -199
  75. package/src/auth/session-cookie-clear.ts +30 -30
  76. package/src/auth/session-reset-link.ts +159 -159
  77. package/src/auth/session-response-sanitizer.ts +151 -151
  78. package/src/auth/types/auth-types.ts +555 -555
  79. package/src/auth/types/index.ts +7 -7
  80. package/src/auth/unauthenticated-routes.ts +2 -2
  81. package/src/auth/utils/idp-client.ts +364 -364
  82. package/src/auth/utils/index.ts +6 -6
  83. package/src/auth/utils/token-utils.ts +243 -243
  84. package/src/client/AuthContext.tsx +192 -192
  85. package/src/client/better-auth-client.ts +70 -70
  86. package/src/client/fetch-with-auth.ts +47 -47
  87. package/src/client/fetchWithSession.ts +21 -21
  88. package/src/client/index.ts +13 -13
  89. package/src/client/useAnonSession.ts +131 -131
  90. package/src/components/SessionSync.tsx +138 -138
  91. package/src/components/SignalRHealthCheck.tsx +131 -131
  92. package/src/components/account/MobileNavDrawer.tsx +305 -305
  93. package/src/components/account/UserAvatarMenu.tsx +277 -277
  94. package/src/components/account/index.ts +13 -13
  95. package/src/components/admin/AlertSettingsTab.tsx +728 -728
  96. package/src/components/admin/AnalyticsTab.tsx +703 -703
  97. package/src/components/admin/DataBrowserTab.tsx +508 -508
  98. package/src/components/admin/LoggingSettingsTab.tsx +665 -665
  99. package/src/components/admin/SessionsTab.tsx +421 -421
  100. package/src/components/admin/StatsTab.tsx +379 -379
  101. package/src/components/admin/VibeAdminContext.tsx +87 -87
  102. package/src/components/admin/VibeAdminLayout.tsx +187 -187
  103. package/src/components/admin/index.ts +59 -59
  104. package/src/components/auth/CredentialSignInForm.tsx +240 -240
  105. package/src/components/auth/FederatedAuthSection.tsx +129 -129
  106. package/src/components/auth/ModeAwareLoginPage.tsx +146 -146
  107. package/src/components/auth/ModeAwareSignupPage.tsx +200 -200
  108. package/src/components/auth/PasswordResetBridge.tsx +30 -30
  109. package/src/components/auth/TraditionalAuthSection.tsx +103 -103
  110. package/src/components/recovery/CompleteStep.tsx +36 -36
  111. package/src/components/recovery/InitiateRecoveryStep.tsx +68 -68
  112. package/src/components/recovery/RequestedStep.tsx +30 -30
  113. package/src/components/recovery/SelectMethodStep.tsx +73 -73
  114. package/src/components/recovery/SetPasswordStep.tsx +118 -118
  115. package/src/components/recovery/VerifyCodeStep.tsx +90 -90
  116. package/src/components/reserved/ReservedRecoveryWarning.tsx +160 -160
  117. package/src/components/reserved/ReservedStatusBox.tsx +118 -118
  118. package/src/components/ui/BetaBadge.tsx +58 -58
  119. package/src/components/ui/Footer.tsx +93 -93
  120. package/src/config/env.ts +55 -55
  121. package/src/config/logger.ts +62 -62
  122. package/src/config/logging-config.ts +82 -82
  123. package/src/config/unauthenticated-routes.ts +19 -19
  124. package/src/config/vibe-log-transport.ts +264 -264
  125. package/src/edge/internal-api-url.ts +65 -65
  126. package/src/edge/middleware.ts +42 -42
  127. package/src/hooks/useAuth.ts +117 -117
  128. package/src/hooks/useAuthSettings.ts +109 -109
  129. package/src/hooks/useAvailableProviders.ts +143 -143
  130. package/src/hooks/usePasswordValidation.ts +127 -127
  131. package/src/hooks/useProfile.ts +82 -82
  132. package/src/hooks/usePublicAuthSettings.ts +171 -171
  133. package/src/hooks/useSessionExpiration.ts +101 -101
  134. package/src/hooks/useViabilitySession.ts +337 -337
  135. package/src/index.ts +64 -64
  136. package/src/lib/anon-session.ts +213 -213
  137. package/src/lib/api-handler.ts +643 -643
  138. package/src/lib/app-slug.ts +228 -228
  139. package/src/lib/authorize-resume.ts +172 -172
  140. package/src/lib/bearer-fetch.ts +31 -31
  141. package/src/lib/client-key.ts +88 -88
  142. package/src/lib/code-step-copy.ts +83 -83
  143. package/src/lib/credential-sign-in-client.ts +101 -101
  144. package/src/lib/demo-mode.ts +18 -18
  145. package/src/lib/device-id.ts +67 -67
  146. package/src/lib/ensure-fresh-access-token.ts +509 -509
  147. package/src/lib/geolocation.ts +265 -265
  148. package/src/lib/idp-client-config.ts +1005 -1005
  149. package/src/lib/idp-fetch.ts +169 -169
  150. package/src/lib/idp-url-guard.ts +37 -37
  151. package/src/lib/internal-api.ts +171 -171
  152. package/src/lib/jwt-decode-client.ts +45 -45
  153. package/src/lib/jwt-decode.ts +82 -82
  154. package/src/lib/lock-window.ts +49 -49
  155. package/src/lib/login-error-message.ts +41 -41
  156. package/src/lib/never-in-response.ts +64 -64
  157. package/src/lib/nextauth-secret.ts +168 -168
  158. package/src/lib/onboarding-proxy.ts +57 -57
  159. package/src/lib/password-rules.ts +50 -50
  160. package/src/lib/rate-limit-service.ts +9 -9
  161. package/src/lib/redis.ts +105 -105
  162. package/src/lib/refresh-token-validator.ts +64 -64
  163. package/src/lib/roles.ts +177 -177
  164. package/src/lib/safe-error-response.ts +149 -149
  165. package/src/lib/secret-validation.ts +8 -8
  166. package/src/lib/session-cookie-shape.ts +185 -185
  167. package/src/lib/session-store.ts +1092 -1092
  168. package/src/lib/session.ts +34 -34
  169. package/src/lib/single-flight.ts +64 -64
  170. package/src/lib/site-logger.ts +245 -245
  171. package/src/lib/standardized-client-api.ts +901 -901
  172. package/src/lib/startup-init.ts +276 -276
  173. package/src/lib/test-aware-get-token.ts +41 -41
  174. package/src/lib/token-expiry.ts +40 -40
  175. package/src/lib/token-lifecycle.ts +546 -546
  176. package/src/lib/token-log-id.ts +69 -69
  177. package/src/lib/twofa-rejection.ts +91 -91
  178. package/src/lib/types/api-responses.ts +336 -336
  179. package/src/lib/user-agent-parser.ts +252 -252
  180. package/src/logging/api/admin-analytics.ts +51 -51
  181. package/src/logging/api/audit-log.ts +53 -53
  182. package/src/logging/components/AdminAnalyticsLayout.tsx +49 -49
  183. package/src/logging/components/AuditLogViewer.tsx +125 -125
  184. package/src/logging/components/ErrorMetricsCard.tsx +98 -98
  185. package/src/logging/components/HealthMetricsCard.tsx +70 -70
  186. package/src/logging/hooks/useAdminAnalytics.ts +22 -22
  187. package/src/logging/hooks/useAuditLog.ts +24 -24
  188. package/src/logging/hooks/useErrorMetrics.ts +40 -40
  189. package/src/logging/hooks/useHealthMetrics.ts +44 -44
  190. package/src/logging/index.ts +18 -18
  191. package/src/logging/types/analytics.ts +81 -81
  192. package/src/logging/types/audit.ts +31 -31
  193. package/src/logging/types/index.ts +3 -3
  194. package/src/middleware/create-middleware.ts +1139 -1138
  195. package/src/middleware/rbac-check.ts +279 -279
  196. package/src/middleware/twofa-presets.ts +224 -224
  197. package/src/models/DecodedAccessToken.ts +16 -16
  198. package/src/models/SessionModel.ts +331 -331
  199. package/src/pages/admin-login/page.tsx +111 -111
  200. package/src/pages/admin-page-permissions/PagePermissionsAdminPage.tsx +527 -527
  201. package/src/pages/admin-page-permissions/index.ts +7 -7
  202. package/src/pages/admin-roles/RolesAdminPage.tsx +533 -533
  203. package/src/pages/admin-roles/index.ts +9 -9
  204. package/src/pages/admin-roles/modals.tsx +469 -469
  205. package/src/pages/client-admin/ClientSiteAdminPage.tsx +382 -382
  206. package/src/pages/client-admin/index.ts +33 -33
  207. package/src/pages/coming-soon/page.tsx +83 -83
  208. package/src/pages/login/page.tsx +338 -338
  209. package/src/pages/onboarding/index.ts +11 -11
  210. package/src/pages/onboarding/page.tsx +212 -212
  211. package/src/pages/profile/EnhancedProfilePage.tsx +514 -514
  212. package/src/pages/profile/index.ts +9 -9
  213. package/src/pages/profile/page.tsx +166 -166
  214. package/src/pages/recovery/page.tsx +267 -267
  215. package/src/pages/roles/MyRolesPage.tsx +211 -211
  216. package/src/pages/roles/components.tsx +294 -294
  217. package/src/pages/roles/index.ts +17 -17
  218. package/src/pages/security/EnhancedSecurityPage.tsx +660 -660
  219. package/src/pages/security/index.ts +12 -12
  220. package/src/pages/security/page.tsx +507 -507
  221. package/src/pages/settings/EnhancedSettingsPage.tsx +642 -642
  222. package/src/pages/settings/index.ts +9 -9
  223. package/src/pages/settings/page.tsx +47 -47
  224. package/src/pages/showcase/ShowcasePage.tsx +532 -532
  225. package/src/pages/showcase/index.ts +13 -13
  226. package/src/pages/test-env/EmergencyLogoutPage.tsx +192 -192
  227. package/src/pages/test-env/JwtInspectPage.tsx +449 -449
  228. package/src/pages/test-env/RefreshTokenPage.tsx +178 -178
  229. package/src/pages/test-env/TestEnvPage.tsx +130 -130
  230. package/src/pages/test-env/guarded.tsx +81 -81
  231. package/src/pages/test-env/index.ts +77 -77
  232. package/src/pages/test-env/redact-credentials.ts +96 -96
  233. package/src/pages/verify-code/page.tsx +746 -746
  234. package/src/routes/account/index.ts +31 -31
  235. package/src/routes/account/masked-info.ts +36 -36
  236. package/src/routes/account/send-code.ts +39 -39
  237. package/src/routes/account/update-phone.ts +13 -13
  238. package/src/routes/account/verify-email.ts +40 -40
  239. package/src/routes/account/verify-sms.ts +40 -40
  240. package/src/routes/auth/credential-login-email-code.ts +6 -6
  241. package/src/routes/auth/credential-login.ts +6 -6
  242. package/src/routes/auth/index.ts +22 -22
  243. package/src/routes/auth/logout.ts +111 -111
  244. package/src/routes/auth/nextauth.ts +45 -45
  245. package/src/routes/auth/passkey-signin.ts +13 -13
  246. package/src/routes/auth/refresh.ts +77 -77
  247. package/src/routes/auth/session-reset.ts +37 -37
  248. package/src/routes/auth/session.ts +261 -261
  249. package/src/routes/auth/settings.ts +181 -181
  250. package/src/routes/auth/viability.ts +519 -519
  251. package/src/routes/index.ts +17 -17
  252. package/src/routes/mfa/backup-code-verify.ts +1 -1
  253. package/src/routes/mfa/backup-codes.ts +10 -10
  254. package/src/routes/mfa/methods.ts +22 -22
  255. package/src/routes/mfa/totp-confirm.ts +10 -10
  256. package/src/routes/mfa/totp-enroll.ts +10 -10
  257. package/src/routes/mfa/totp-verify.ts +14 -14
  258. package/src/routes/onboarding/index.ts +15 -15
  259. package/src/routes/onboarding/send-email-code.ts +2 -2
  260. package/src/routes/onboarding/set-password.ts +2 -2
  261. package/src/routes/onboarding/verify-code.ts +2 -2
  262. package/src/routes/onboarding/verify-welcome-email.ts +2 -2
  263. package/src/routes/passkeys/list.ts +10 -10
  264. package/src/routes/passkeys/manage.ts +23 -23
  265. package/src/routes/passkeys/register-options.ts +10 -10
  266. package/src/routes/passkeys/register-verify.ts +10 -10
  267. package/src/routes/session/index.ts +7 -7
  268. package/src/routes/session/refresh-viability.ts +17 -17
  269. package/src/server/auth-guard.ts +203 -203
  270. package/src/server/auth.ts +486 -486
  271. package/src/server/decode-session.ts +309 -309
  272. package/src/server/slim-middleware.ts +117 -117
  273. package/src/server/verified-session-token.ts +103 -103
  274. package/src/server/with-auth.ts +93 -93
  275. package/src/services/signalrActivityService.ts +258 -258
  276. package/src/stores/authStore.ts +1900 -1900
  277. package/src/templates/instrumentation.ts +60 -60
  278. package/src/theme/ThemeProvider.tsx +39 -39
  279. package/src/theme/default.ts +33 -33
  280. package/src/theme/index.ts +31 -31
  281. package/src/theme/types.ts +69 -69
  282. package/src/theme/useTheme.ts +57 -57
  283. package/src/theme/utils.ts +40 -40
  284. package/src/types/api.ts +12 -12
  285. package/src/types/auth.d.ts +23 -23
  286. package/src/types/auth.ts +48 -48
  287. package/src/types/logging.ts +11 -11
  288. package/src/types/recovery.ts +54 -54
  289. package/src/utils/api.ts +401 -401
  290. package/src/utils/circuitBreaker.ts +40 -40
  291. package/src/utils/error-message.ts +108 -108
  292. package/src/utils/layout/reservedSpace.ts +124 -124
  293. package/src/utils/logout.ts +30 -30
  294. package/src/vibe/client.ts +877 -877
  295. package/src/vibe/enterprise-auth.ts +208 -208
  296. package/src/vibe/errors.ts +209 -209
  297. package/src/vibe/generic.ts +339 -339
  298. package/src/vibe/hooks/index.ts +367 -367
  299. package/src/vibe/index.ts +133 -133
  300. package/src/vibe/sessions.ts +925 -899
  301. 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
+ }