@payez/next-mvp 3.9.1 → 4.0.1
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.
- package/package.json +6 -18
- package/src/api/auth-handler.ts +550 -549
- package/src/api-handlers/account/change-password.ts +5 -8
- package/src/api-handlers/admin/analytics.ts +4 -6
- package/src/api-handlers/admin/audit.ts +5 -7
- package/src/api-handlers/admin/index.ts +1 -2
- package/src/api-handlers/admin/redis-sessions.ts +6 -8
- package/src/api-handlers/admin/sessions.ts +5 -7
- package/src/api-handlers/admin/site-logs.ts +8 -10
- package/src/api-handlers/admin/stats.ts +4 -6
- package/src/api-handlers/admin/users.ts +5 -7
- package/src/api-handlers/admin/vibe-data.ts +10 -12
- package/src/api-handlers/auth/refresh.ts +5 -7
- package/src/api-handlers/auth/signout.ts +5 -6
- package/src/api-handlers/auth/status.ts +4 -7
- package/src/api-handlers/auth/update-session.ts +123 -125
- package/src/api-handlers/auth/verify-code.ts +9 -13
- package/src/api-handlers/session/viability.ts +10 -47
- package/src/api-handlers/test/force-expire.ts +4 -11
- package/src/auth/auth-decision.ts +1 -1
- package/src/auth/better-auth.ts +138 -141
- package/src/auth/route-config.ts +219 -219
- package/src/auth/utils/token-utils.ts +0 -1
- package/src/client/AuthContext.tsx +6 -2
- package/src/client/fetch-with-auth.ts +47 -47
- package/src/components/SessionSync.tsx +6 -5
- package/src/components/account/MobileNavDrawer.tsx +3 -3
- package/src/components/account/UserAvatarMenu.tsx +6 -3
- package/src/components/admin/VibeAdminLayout.tsx +4 -2
- package/src/config/logger.ts +1 -1
- package/src/hooks/useAuth.ts +117 -115
- package/src/hooks/useAuthSettings.ts +2 -2
- package/src/hooks/useAvailableProviders.ts +9 -5
- package/src/hooks/useSessionExpiration.ts +101 -102
- package/src/hooks/useViabilitySession.ts +336 -335
- package/src/index.ts +60 -63
- package/src/lib/api-handler.ts +0 -1
- package/src/lib/app-slug.ts +6 -6
- package/src/lib/standardized-client-api.ts +901 -895
- package/src/lib/startup-init.ts +243 -247
- package/src/lib/test-aware-get-token.ts +22 -12
- package/src/lib/token-lifecycle.ts +12 -53
- package/src/pages/admin-login/page.tsx +9 -17
- package/src/pages/client-admin/ClientSiteAdminPage.tsx +4 -2
- package/src/pages/login/page.tsx +21 -28
- package/src/pages/showcase/ShowcasePage.tsx +4 -2
- package/src/pages/test-env/EmergencyLogoutPage.tsx +7 -6
- package/src/pages/test-env/JwtInspectPage.tsx +5 -3
- package/src/pages/test-env/RefreshTokenPage.tsx +157 -155
- package/src/pages/test-env/TestEnvPage.tsx +4 -2
- package/src/pages/verify-code/page.tsx +10 -6
- package/src/routes/auth/logout.ts +7 -25
- package/src/routes/auth/nextauth.ts +45 -71
- package/src/routes/auth/session.ts +25 -50
- package/src/routes/auth/viability.ts +7 -19
- package/src/server/auth.ts +60 -0
- package/src/stores/authStore.ts +1899 -1904
- package/src/utils/logout.ts +30 -30
- package/dist/api/auth-handler.d.ts +0 -67
- package/dist/api/auth-handler.js +0 -397
- package/dist/api/index.d.ts +0 -10
- package/dist/api/index.js +0 -19
- package/dist/api-handlers/account/change-password.d.ts +0 -9
- package/dist/api-handlers/account/change-password.js +0 -112
- package/dist/api-handlers/account/masked-info.d.ts +0 -2
- package/dist/api-handlers/account/masked-info.js +0 -41
- package/dist/api-handlers/account/profile.d.ts +0 -3
- package/dist/api-handlers/account/profile.js +0 -63
- package/dist/api-handlers/account/recovery/initiate.d.ts +0 -2
- package/dist/api-handlers/account/recovery/initiate.js +0 -26
- package/dist/api-handlers/account/recovery/send-code.d.ts +0 -2
- package/dist/api-handlers/account/recovery/send-code.js +0 -28
- package/dist/api-handlers/account/recovery/verify-code.d.ts +0 -2
- package/dist/api-handlers/account/recovery/verify-code.js +0 -28
- package/dist/api-handlers/account/reset-password.d.ts +0 -2
- package/dist/api-handlers/account/reset-password.js +0 -26
- package/dist/api-handlers/account/send-code.d.ts +0 -24
- package/dist/api-handlers/account/send-code.js +0 -60
- package/dist/api-handlers/account/update-phone.d.ts +0 -27
- package/dist/api-handlers/account/update-phone.js +0 -64
- package/dist/api-handlers/account/validate-password.d.ts +0 -17
- package/dist/api-handlers/account/validate-password.js +0 -81
- package/dist/api-handlers/account/verify-email.d.ts +0 -26
- package/dist/api-handlers/account/verify-email.js +0 -106
- package/dist/api-handlers/account/verify-sms.d.ts +0 -26
- package/dist/api-handlers/account/verify-sms.js +0 -106
- package/dist/api-handlers/admin/analytics.d.ts +0 -20
- package/dist/api-handlers/admin/analytics.js +0 -379
- package/dist/api-handlers/admin/audit.d.ts +0 -20
- package/dist/api-handlers/admin/audit.js +0 -214
- package/dist/api-handlers/admin/index.d.ts +0 -22
- package/dist/api-handlers/admin/index.js +0 -43
- package/dist/api-handlers/admin/redis-sessions.d.ts +0 -36
- package/dist/api-handlers/admin/redis-sessions.js +0 -204
- package/dist/api-handlers/admin/sessions.d.ts +0 -21
- package/dist/api-handlers/admin/sessions.js +0 -284
- package/dist/api-handlers/admin/site-logs.d.ts +0 -46
- package/dist/api-handlers/admin/site-logs.js +0 -318
- package/dist/api-handlers/admin/stats.d.ts +0 -21
- package/dist/api-handlers/admin/stats.js +0 -240
- package/dist/api-handlers/admin/users.d.ts +0 -20
- package/dist/api-handlers/admin/users.js +0 -222
- package/dist/api-handlers/admin/vibe-data.d.ts +0 -80
- package/dist/api-handlers/admin/vibe-data.js +0 -268
- package/dist/api-handlers/anon/preferences.d.ts +0 -37
- package/dist/api-handlers/anon/preferences.js +0 -96
- package/dist/api-handlers/auth/jwks.d.ts +0 -2
- package/dist/api-handlers/auth/jwks.js +0 -24
- package/dist/api-handlers/auth/login.d.ts +0 -42
- package/dist/api-handlers/auth/login.js +0 -178
- package/dist/api-handlers/auth/refresh.d.ts +0 -74
- package/dist/api-handlers/auth/refresh.js +0 -635
- package/dist/api-handlers/auth/signout.d.ts +0 -37
- package/dist/api-handlers/auth/signout.js +0 -187
- package/dist/api-handlers/auth/status.d.ts +0 -8
- package/dist/api-handlers/auth/status.js +0 -26
- package/dist/api-handlers/auth/update-session.d.ts +0 -37
- package/dist/api-handlers/auth/update-session.js +0 -95
- package/dist/api-handlers/auth/validate.d.ts +0 -6
- package/dist/api-handlers/auth/validate.js +0 -43
- package/dist/api-handlers/auth/verify-code.d.ts +0 -43
- package/dist/api-handlers/auth/verify-code.js +0 -94
- package/dist/api-handlers/session/refresh-viability.d.ts +0 -14
- package/dist/api-handlers/session/refresh-viability.js +0 -39
- package/dist/api-handlers/session/viability.d.ts +0 -13
- package/dist/api-handlers/session/viability.js +0 -146
- package/dist/api-handlers/test/force-expire.d.ts +0 -23
- package/dist/api-handlers/test/force-expire.js +0 -65
- package/dist/auth/auth-decision.d.ts +0 -39
- package/dist/auth/auth-decision.js +0 -182
- package/dist/auth/auth-options.d.ts +0 -57
- package/dist/auth/auth-options.js +0 -213
- package/dist/auth/better-auth.d.ts +0 -82
- package/dist/auth/better-auth.js +0 -122
- package/dist/auth/callbacks/index.d.ts +0 -6
- package/dist/auth/callbacks/index.js +0 -12
- package/dist/auth/callbacks/jwt.d.ts +0 -45
- package/dist/auth/callbacks/jwt.js +0 -305
- package/dist/auth/callbacks/session.d.ts +0 -60
- package/dist/auth/callbacks/session.js +0 -170
- package/dist/auth/callbacks/signin.d.ts +0 -23
- package/dist/auth/callbacks/signin.js +0 -44
- package/dist/auth/events/index.d.ts +0 -4
- package/dist/auth/events/index.js +0 -8
- package/dist/auth/events/signout.d.ts +0 -17
- package/dist/auth/events/signout.js +0 -32
- package/dist/auth/providers/credentials.d.ts +0 -32
- package/dist/auth/providers/credentials.js +0 -223
- package/dist/auth/providers/index.d.ts +0 -5
- package/dist/auth/providers/index.js +0 -21
- package/dist/auth/providers/oauth.d.ts +0 -26
- package/dist/auth/providers/oauth.js +0 -105
- package/dist/auth/route-config.d.ts +0 -66
- package/dist/auth/route-config.js +0 -190
- package/dist/auth/types/auth-types.d.ts +0 -417
- package/dist/auth/types/auth-types.js +0 -53
- package/dist/auth/types/index.d.ts +0 -6
- package/dist/auth/types/index.js +0 -22
- package/dist/auth/unauthenticated-routes.d.ts +0 -1
- package/dist/auth/unauthenticated-routes.js +0 -19
- package/dist/auth/utils/idp-client.d.ts +0 -94
- package/dist/auth/utils/idp-client.js +0 -384
- package/dist/auth/utils/index.d.ts +0 -5
- package/dist/auth/utils/index.js +0 -21
- package/dist/auth/utils/token-utils.d.ts +0 -84
- package/dist/auth/utils/token-utils.js +0 -219
- package/dist/client/AuthContext.d.ts +0 -19
- package/dist/client/AuthContext.js +0 -112
- package/dist/client/better-auth-client.d.ts +0 -1020
- package/dist/client/better-auth-client.js +0 -68
- package/dist/client/fetch-with-auth.d.ts +0 -11
- package/dist/client/fetch-with-auth.js +0 -44
- package/dist/client/fetchWithSession.d.ts +0 -3
- package/dist/client/fetchWithSession.js +0 -24
- package/dist/client/index.d.ts +0 -9
- package/dist/client/index.js +0 -20
- package/dist/client/useAnonSession.d.ts +0 -36
- package/dist/client/useAnonSession.js +0 -99
- package/dist/components/SessionSync.d.ts +0 -13
- package/dist/components/SessionSync.js +0 -119
- package/dist/components/SignalRHealthCheck.d.ts +0 -10
- package/dist/components/SignalRHealthCheck.js +0 -97
- package/dist/components/account/MobileNavDrawer.d.ts +0 -32
- package/dist/components/account/MobileNavDrawer.js +0 -81
- package/dist/components/account/UserAvatarMenu.d.ts +0 -20
- package/dist/components/account/UserAvatarMenu.js +0 -88
- package/dist/components/account/index.d.ts +0 -9
- package/dist/components/account/index.js +0 -13
- package/dist/components/admin/AlertSettingsTab.d.ts +0 -48
- package/dist/components/admin/AlertSettingsTab.js +0 -351
- package/dist/components/admin/AnalyticsTab.d.ts +0 -22
- package/dist/components/admin/AnalyticsTab.js +0 -167
- package/dist/components/admin/DataBrowserTab.d.ts +0 -19
- package/dist/components/admin/DataBrowserTab.js +0 -252
- package/dist/components/admin/LoggingSettingsTab.d.ts +0 -73
- package/dist/components/admin/LoggingSettingsTab.js +0 -339
- package/dist/components/admin/SessionsTab.d.ts +0 -37
- package/dist/components/admin/SessionsTab.js +0 -165
- package/dist/components/admin/StatsTab.d.ts +0 -53
- package/dist/components/admin/StatsTab.js +0 -161
- package/dist/components/admin/VibeAdminContext.d.ts +0 -32
- package/dist/components/admin/VibeAdminContext.js +0 -38
- package/dist/components/admin/VibeAdminLayout.d.ts +0 -11
- package/dist/components/admin/VibeAdminLayout.js +0 -69
- package/dist/components/admin/index.d.ts +0 -29
- package/dist/components/admin/index.js +0 -44
- package/dist/components/auth/FederatedAuthSection.d.ts +0 -8
- package/dist/components/auth/FederatedAuthSection.js +0 -45
- package/dist/components/auth/ModeAwareLoginPage.d.ts +0 -10
- package/dist/components/auth/ModeAwareLoginPage.js +0 -42
- package/dist/components/auth/ModeAwareSignupPage.d.ts +0 -9
- package/dist/components/auth/ModeAwareSignupPage.js +0 -78
- package/dist/components/auth/TraditionalAuthSection.d.ts +0 -14
- package/dist/components/auth/TraditionalAuthSection.js +0 -20
- package/dist/components/recovery/CompleteStep.d.ts +0 -5
- package/dist/components/recovery/CompleteStep.js +0 -8
- package/dist/components/recovery/InitiateRecoveryStep.d.ts +0 -8
- package/dist/components/recovery/InitiateRecoveryStep.js +0 -20
- package/dist/components/recovery/SelectMethodStep.d.ts +0 -8
- package/dist/components/recovery/SelectMethodStep.js +0 -8
- package/dist/components/recovery/SetPasswordStep.d.ts +0 -6
- package/dist/components/recovery/SetPasswordStep.js +0 -20
- package/dist/components/recovery/VerifyCodeStep.d.ts +0 -10
- package/dist/components/recovery/VerifyCodeStep.js +0 -24
- package/dist/components/reserved/ReservedRecoveryWarning.d.ts +0 -38
- package/dist/components/reserved/ReservedRecoveryWarning.js +0 -92
- package/dist/components/reserved/ReservedStatusBox.d.ts +0 -30
- package/dist/components/reserved/ReservedStatusBox.js +0 -71
- package/dist/components/ui/BetaBadge.d.ts +0 -29
- package/dist/components/ui/BetaBadge.js +0 -38
- package/dist/components/ui/Footer.d.ts +0 -37
- package/dist/components/ui/Footer.js +0 -41
- package/dist/config/env.d.ts +0 -66
- package/dist/config/env.js +0 -57
- package/dist/config/logger.d.ts +0 -57
- package/dist/config/logger.js +0 -73
- package/dist/config/logging-config.d.ts +0 -30
- package/dist/config/logging-config.js +0 -122
- package/dist/config/unauthenticated-routes.d.ts +0 -17
- package/dist/config/unauthenticated-routes.js +0 -24
- package/dist/config/vibe-log-transport.d.ts +0 -81
- package/dist/config/vibe-log-transport.js +0 -212
- package/dist/edge/internal-api-url.d.ts +0 -53
- package/dist/edge/internal-api-url.js +0 -63
- package/dist/edge/middleware.d.ts +0 -14
- package/dist/edge/middleware.js +0 -32
- package/dist/hooks/useAuth.d.ts +0 -23
- package/dist/hooks/useAuth.js +0 -81
- package/dist/hooks/useAuthSettings.d.ts +0 -59
- package/dist/hooks/useAuthSettings.js +0 -93
- package/dist/hooks/useAvailableProviders.d.ts +0 -45
- package/dist/hooks/useAvailableProviders.js +0 -108
- package/dist/hooks/usePasswordValidation.d.ts +0 -27
- package/dist/hooks/usePasswordValidation.js +0 -102
- package/dist/hooks/useProfile.d.ts +0 -15
- package/dist/hooks/useProfile.js +0 -59
- package/dist/hooks/usePublicAuthSettings.d.ts +0 -56
- package/dist/hooks/usePublicAuthSettings.js +0 -131
- package/dist/hooks/useSessionExpiration.d.ts +0 -57
- package/dist/hooks/useSessionExpiration.js +0 -72
- package/dist/hooks/useViabilitySession.d.ts +0 -75
- package/dist/hooks/useViabilitySession.js +0 -268
- package/dist/index.d.ts +0 -12
- package/dist/index.js +0 -55
- package/dist/lib/anon-session.d.ts +0 -74
- package/dist/lib/anon-session.js +0 -169
- package/dist/lib/api-handler.d.ts +0 -123
- package/dist/lib/api-handler.js +0 -478
- package/dist/lib/app-slug.d.ts +0 -95
- package/dist/lib/app-slug.js +0 -172
- package/dist/lib/demo-mode.d.ts +0 -6
- package/dist/lib/demo-mode.js +0 -16
- package/dist/lib/geolocation.d.ts +0 -64
- package/dist/lib/geolocation.js +0 -235
- package/dist/lib/idp-client-config.d.ts +0 -75
- package/dist/lib/idp-client-config.js +0 -425
- package/dist/lib/idp-fetch.d.ts +0 -14
- package/dist/lib/idp-fetch.js +0 -91
- package/dist/lib/internal-api.d.ts +0 -87
- package/dist/lib/internal-api.js +0 -122
- package/dist/lib/jwt-decode-client.d.ts +0 -10
- package/dist/lib/jwt-decode-client.js +0 -46
- package/dist/lib/jwt-decode.d.ts +0 -48
- package/dist/lib/jwt-decode.js +0 -57
- package/dist/lib/nextauth-secret.d.ts +0 -10
- package/dist/lib/nextauth-secret.js +0 -100
- package/dist/lib/rate-limit-service.d.ts +0 -23
- package/dist/lib/rate-limit-service.js +0 -6
- package/dist/lib/redis.d.ts +0 -5
- package/dist/lib/redis.js +0 -28
- package/dist/lib/refresh-token-validator.d.ts +0 -13
- package/dist/lib/refresh-token-validator.js +0 -117
- package/dist/lib/roles.d.ts +0 -145
- package/dist/lib/roles.js +0 -168
- package/dist/lib/secret-validation.d.ts +0 -4
- package/dist/lib/secret-validation.js +0 -14
- package/dist/lib/session-store.d.ts +0 -170
- package/dist/lib/session-store.js +0 -545
- package/dist/lib/session.d.ts +0 -21
- package/dist/lib/session.js +0 -26
- package/dist/lib/site-logger.d.ts +0 -214
- package/dist/lib/site-logger.js +0 -210
- package/dist/lib/standardized-client-api.d.ts +0 -161
- package/dist/lib/standardized-client-api.js +0 -786
- package/dist/lib/startup-init.d.ts +0 -40
- package/dist/lib/startup-init.js +0 -261
- package/dist/lib/test-aware-get-token.d.ts +0 -2
- package/dist/lib/test-aware-get-token.js +0 -81
- package/dist/lib/token-expiry.d.ts +0 -14
- package/dist/lib/token-expiry.js +0 -39
- package/dist/lib/token-lifecycle.d.ts +0 -52
- package/dist/lib/token-lifecycle.js +0 -398
- package/dist/lib/types/api-responses.d.ts +0 -128
- package/dist/lib/types/api-responses.js +0 -171
- package/dist/lib/user-agent-parser.d.ts +0 -50
- package/dist/lib/user-agent-parser.js +0 -220
- package/dist/logging/api/admin-analytics.d.ts +0 -3
- package/dist/logging/api/admin-analytics.js +0 -45
- package/dist/logging/api/audit-log.d.ts +0 -3
- package/dist/logging/api/audit-log.js +0 -52
- package/dist/logging/components/AdminAnalyticsLayout.d.ts +0 -10
- package/dist/logging/components/AdminAnalyticsLayout.js +0 -11
- package/dist/logging/components/AuditLogViewer.d.ts +0 -7
- package/dist/logging/components/AuditLogViewer.js +0 -51
- package/dist/logging/components/ErrorMetricsCard.d.ts +0 -7
- package/dist/logging/components/ErrorMetricsCard.js +0 -16
- package/dist/logging/components/HealthMetricsCard.d.ts +0 -7
- package/dist/logging/components/HealthMetricsCard.js +0 -19
- package/dist/logging/hooks/useAdminAnalytics.d.ts +0 -24
- package/dist/logging/hooks/useAdminAnalytics.js +0 -22
- package/dist/logging/hooks/useAuditLog.d.ts +0 -6
- package/dist/logging/hooks/useAuditLog.js +0 -25
- package/dist/logging/hooks/useErrorMetrics.d.ts +0 -6
- package/dist/logging/hooks/useErrorMetrics.js +0 -38
- package/dist/logging/hooks/useHealthMetrics.d.ts +0 -6
- package/dist/logging/hooks/useHealthMetrics.js +0 -41
- package/dist/logging/index.d.ts +0 -11
- package/dist/logging/index.js +0 -40
- package/dist/logging/types/analytics.d.ts +0 -68
- package/dist/logging/types/analytics.js +0 -3
- package/dist/logging/types/audit.d.ts +0 -29
- package/dist/logging/types/audit.js +0 -2
- package/dist/logging/types/index.d.ts +0 -2
- package/dist/logging/types/index.js +0 -19
- package/dist/middleware/auth-decision.d.ts +0 -33
- package/dist/middleware/auth-decision.js +0 -65
- package/dist/middleware/create-middleware.d.ts +0 -102
- package/dist/middleware/create-middleware.js +0 -469
- package/dist/middleware/rbac-check.d.ts +0 -51
- package/dist/middleware/rbac-check.js +0 -219
- package/dist/middleware/twofa-presets.d.ts +0 -134
- package/dist/middleware/twofa-presets.js +0 -175
- package/dist/models/DecodedAccessToken.d.ts +0 -17
- package/dist/models/DecodedAccessToken.js +0 -2
- package/dist/models/SessionModel.d.ts +0 -122
- package/dist/models/SessionModel.js +0 -136
- package/dist/pages/admin-login/page.d.ts +0 -31
- package/dist/pages/admin-login/page.js +0 -83
- package/dist/pages/admin-page-permissions/PagePermissionsAdminPage.d.ts +0 -18
- package/dist/pages/admin-page-permissions/PagePermissionsAdminPage.js +0 -276
- package/dist/pages/admin-page-permissions/index.d.ts +0 -6
- package/dist/pages/admin-page-permissions/index.js +0 -13
- package/dist/pages/admin-roles/RolesAdminPage.d.ts +0 -16
- package/dist/pages/admin-roles/RolesAdminPage.js +0 -261
- package/dist/pages/admin-roles/index.d.ts +0 -8
- package/dist/pages/admin-roles/index.js +0 -15
- package/dist/pages/admin-roles/modals.d.ts +0 -72
- package/dist/pages/admin-roles/modals.js +0 -154
- package/dist/pages/client-admin/ClientSiteAdminPage.d.ts +0 -79
- package/dist/pages/client-admin/ClientSiteAdminPage.js +0 -177
- package/dist/pages/client-admin/index.d.ts +0 -32
- package/dist/pages/client-admin/index.js +0 -37
- package/dist/pages/coming-soon/page.d.ts +0 -8
- package/dist/pages/coming-soon/page.js +0 -28
- package/dist/pages/login/page.d.ts +0 -22
- package/dist/pages/login/page.js +0 -239
- package/dist/pages/profile/EnhancedProfilePage.d.ts +0 -13
- package/dist/pages/profile/EnhancedProfilePage.js +0 -150
- package/dist/pages/profile/index.d.ts +0 -8
- package/dist/pages/profile/index.js +0 -16
- package/dist/pages/profile/page.d.ts +0 -19
- package/dist/pages/profile/page.js +0 -47
- package/dist/pages/profile/profile-patch.d.ts +0 -1
- package/dist/pages/profile/profile-patch.js +0 -281
- package/dist/pages/recovery/page.d.ts +0 -1
- package/dist/pages/recovery/page.js +0 -142
- package/dist/pages/roles/MyRolesPage.d.ts +0 -24
- package/dist/pages/roles/MyRolesPage.js +0 -71
- package/dist/pages/roles/components.d.ts +0 -63
- package/dist/pages/roles/components.js +0 -108
- package/dist/pages/roles/index.d.ts +0 -8
- package/dist/pages/roles/index.js +0 -19
- package/dist/pages/security/EnhancedSecurityPage.d.ts +0 -14
- package/dist/pages/security/EnhancedSecurityPage.js +0 -248
- package/dist/pages/security/index.d.ts +0 -8
- package/dist/pages/security/index.js +0 -16
- package/dist/pages/security/page.d.ts +0 -21
- package/dist/pages/security/page.js +0 -212
- package/dist/pages/security/security-patch.d.ts +0 -1
- package/dist/pages/security/security-patch.js +0 -302
- package/dist/pages/settings/EnhancedSettingsPage.d.ts +0 -46
- package/dist/pages/settings/EnhancedSettingsPage.js +0 -231
- package/dist/pages/settings/index.d.ts +0 -8
- package/dist/pages/settings/index.js +0 -16
- package/dist/pages/settings/page.d.ts +0 -7
- package/dist/pages/settings/page.js +0 -26
- package/dist/pages/showcase/ShowcasePage.d.ts +0 -13
- package/dist/pages/showcase/ShowcasePage.js +0 -140
- package/dist/pages/showcase/index.d.ts +0 -12
- package/dist/pages/showcase/index.js +0 -17
- package/dist/pages/test-env/EmergencyLogoutPage.d.ts +0 -14
- package/dist/pages/test-env/EmergencyLogoutPage.js +0 -98
- package/dist/pages/test-env/JwtInspectPage.d.ts +0 -14
- package/dist/pages/test-env/JwtInspectPage.js +0 -114
- package/dist/pages/test-env/RefreshTokenPage.d.ts +0 -15
- package/dist/pages/test-env/RefreshTokenPage.js +0 -91
- package/dist/pages/test-env/TestEnvPage.d.ts +0 -13
- package/dist/pages/test-env/TestEnvPage.js +0 -49
- package/dist/pages/test-env/index.d.ts +0 -24
- package/dist/pages/test-env/index.js +0 -32
- package/dist/pages/verify-code/page.d.ts +0 -30
- package/dist/pages/verify-code/page.js +0 -408
- package/dist/routes/account/index.d.ts +0 -28
- package/dist/routes/account/index.js +0 -71
- package/dist/routes/account/masked-info.d.ts +0 -33
- package/dist/routes/account/masked-info.js +0 -39
- package/dist/routes/account/send-code.d.ts +0 -37
- package/dist/routes/account/send-code.js +0 -42
- package/dist/routes/account/update-phone.d.ts +0 -13
- package/dist/routes/account/update-phone.js +0 -17
- package/dist/routes/account/verify-email.d.ts +0 -38
- package/dist/routes/account/verify-email.js +0 -43
- package/dist/routes/account/verify-sms.d.ts +0 -38
- package/dist/routes/account/verify-sms.js +0 -43
- package/dist/routes/auth/index.d.ts +0 -19
- package/dist/routes/auth/index.js +0 -64
- package/dist/routes/auth/logout.d.ts +0 -31
- package/dist/routes/auth/logout.js +0 -113
- package/dist/routes/auth/nextauth.d.ts +0 -19
- package/dist/routes/auth/nextauth.js +0 -72
- package/dist/routes/auth/refresh.d.ts +0 -30
- package/dist/routes/auth/refresh.js +0 -51
- package/dist/routes/auth/session.d.ts +0 -43
- package/dist/routes/auth/session.js +0 -179
- package/dist/routes/auth/settings.d.ts +0 -25
- package/dist/routes/auth/settings.js +0 -55
- package/dist/routes/auth/viability.d.ts +0 -52
- package/dist/routes/auth/viability.js +0 -201
- package/dist/routes/index.d.ts +0 -12
- package/dist/routes/index.js +0 -54
- package/dist/routes/session/index.d.ts +0 -6
- package/dist/routes/session/index.js +0 -10
- package/dist/routes/session/refresh-viability.d.ts +0 -16
- package/dist/routes/session/refresh-viability.js +0 -20
- package/dist/server/auth-guard.d.ts +0 -46
- package/dist/server/auth-guard.js +0 -128
- package/dist/server/decode-session.d.ts +0 -30
- package/dist/server/decode-session.js +0 -78
- package/dist/server/slim-middleware.d.ts +0 -23
- package/dist/server/slim-middleware.js +0 -89
- package/dist/server/with-auth.d.ts +0 -33
- package/dist/server/with-auth.js +0 -59
- package/dist/services/signalrActivityService.d.ts +0 -44
- package/dist/services/signalrActivityService.js +0 -257
- package/dist/stores/authStore.d.ts +0 -154
- package/dist/stores/authStore.js +0 -1531
- package/dist/theme/ThemeProvider.d.ts +0 -14
- package/dist/theme/ThemeProvider.js +0 -28
- package/dist/theme/default.d.ts +0 -8
- package/dist/theme/default.js +0 -33
- package/dist/theme/index.d.ts +0 -15
- package/dist/theme/index.js +0 -25
- package/dist/theme/types.d.ts +0 -56
- package/dist/theme/types.js +0 -8
- package/dist/theme/useTheme.d.ts +0 -60
- package/dist/theme/useTheme.js +0 -63
- package/dist/theme/utils.d.ts +0 -13
- package/dist/theme/utils.js +0 -39
- package/dist/types/api.d.ts +0 -134
- package/dist/types/api.js +0 -44
- package/dist/types/auth.d.ts +0 -19
- package/dist/types/auth.js +0 -2
- package/dist/types/logging.d.ts +0 -42
- package/dist/types/logging.js +0 -2
- package/dist/types/recovery.d.ts +0 -48
- package/dist/types/recovery.js +0 -2
- package/dist/types/security.d.ts +0 -1
- package/dist/types/security.js +0 -2
- package/dist/utils/api.d.ts +0 -85
- package/dist/utils/api.js +0 -287
- package/dist/utils/circuitBreaker.d.ts +0 -43
- package/dist/utils/circuitBreaker.js +0 -91
- package/dist/utils/error-message.d.ts +0 -1
- package/dist/utils/error-message.js +0 -103
- package/dist/utils/layout/reservedSpace.d.ts +0 -59
- package/dist/utils/layout/reservedSpace.js +0 -102
- package/dist/utils/logout.d.ts +0 -14
- package/dist/utils/logout.js +0 -32
- package/dist/vibe/client.d.ts +0 -261
- package/dist/vibe/client.js +0 -445
- package/dist/vibe/enterprise-auth.d.ts +0 -106
- package/dist/vibe/enterprise-auth.js +0 -173
- package/dist/vibe/errors.d.ts +0 -83
- package/dist/vibe/errors.js +0 -146
- package/dist/vibe/generic.d.ts +0 -234
- package/dist/vibe/generic.js +0 -369
- package/dist/vibe/hooks/index.d.ts +0 -169
- package/dist/vibe/hooks/index.js +0 -252
- package/dist/vibe/index.d.ts +0 -25
- package/dist/vibe/index.js +0 -72
- package/dist/vibe/sessions.d.ts +0 -161
- package/dist/vibe/sessions.js +0 -391
- package/dist/vibe/types.d.ts +0 -353
- package/dist/vibe/types.js +0 -315
- package/src/auth/auth-options.ts +0 -237
- package/src/auth/callbacks/index.ts +0 -7
- package/src/auth/callbacks/jwt.ts +0 -382
- package/src/auth/callbacks/session.ts +0 -243
- package/src/auth/callbacks/signin.ts +0 -56
- package/src/auth/events/index.ts +0 -5
- package/src/auth/events/signout.ts +0 -33
- package/src/auth/providers/credentials.ts +0 -256
- package/src/auth/providers/index.ts +0 -6
- package/src/auth/providers/oauth.ts +0 -114
- package/src/lib/nextauth-secret.ts +0 -121
- package/src/types/next-auth.d.ts +0 -15
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* JWT Callback
|
|
4
|
-
*
|
|
5
|
-
* Minimal token strategy - only store redisSessionId in JWT.
|
|
6
|
-
* All session data lives in Redis, not in the browser cookie.
|
|
7
|
-
*
|
|
8
|
-
* HANDLES:
|
|
9
|
-
* - Initial sign-in (credentials): Store redisSessionId from authorize()
|
|
10
|
-
* - Initial sign-in (OAuth): Register with IDP, create session, store redisSessionId
|
|
11
|
-
* - Subsequent requests: Validate session exists, return token
|
|
12
|
-
*
|
|
13
|
-
* @version 1.0.0
|
|
14
|
-
* @since auth-refactor-2026-01
|
|
15
|
-
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.jwtCallback = jwtCallback;
|
|
18
|
-
const crypto_1 = require("crypto");
|
|
19
|
-
const session_store_1 = require("../../lib/session-store");
|
|
20
|
-
const idp_client_config_1 = require("../../lib/idp-client-config");
|
|
21
|
-
const idp_client_1 = require("../utils/idp-client");
|
|
22
|
-
const token_utils_1 = require("../utils/token-utils");
|
|
23
|
-
// NOTE: Using any for sessionData until Phase 3 normalizes types
|
|
24
|
-
// ============================================================================
|
|
25
|
-
// VIBE ROLE FETCHING
|
|
26
|
-
// ============================================================================
|
|
27
|
-
/**
|
|
28
|
-
* Generate HMAC signature for Vibe API request.
|
|
29
|
-
*/
|
|
30
|
-
function generateVibeSignature(endpoint, clientId, timestamp) {
|
|
31
|
-
const signingKey = process.env.VIBE_SIGNING_KEY;
|
|
32
|
-
if (!signingKey) {
|
|
33
|
-
return '';
|
|
34
|
-
}
|
|
35
|
-
const stringToSign = `${timestamp}|GET|${endpoint}|${clientId}`;
|
|
36
|
-
return (0, crypto_1.createHmac)('sha256', Buffer.from(signingKey, 'base64'))
|
|
37
|
-
.update(stringToSign)
|
|
38
|
-
.digest('base64');
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Fetch user's roles from Vibe API.
|
|
42
|
-
* Returns empty array on failure (non-blocking).
|
|
43
|
-
* Uses HMAC signature for authentication when signing key is configured.
|
|
44
|
-
*/
|
|
45
|
-
async function fetchVibeRoles(userId, clientId) {
|
|
46
|
-
const vibeApiUrl = process.env.VIBE_API_URL;
|
|
47
|
-
if (!vibeApiUrl) {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
const endpoint = `/api/v1/users/${userId}/roles`;
|
|
51
|
-
const timestamp = Math.floor(Date.now() / 1000);
|
|
52
|
-
const signature = generateVibeSignature(endpoint, clientId, timestamp);
|
|
53
|
-
// Build headers with optional signature
|
|
54
|
-
const headers = {
|
|
55
|
-
'Accept': 'application/json',
|
|
56
|
-
'X-Client-Id': clientId,
|
|
57
|
-
'X-Vibe-Client-Id': clientId,
|
|
58
|
-
};
|
|
59
|
-
if (signature) {
|
|
60
|
-
headers['X-Vibe-Timestamp'] = String(timestamp);
|
|
61
|
-
headers['X-Vibe-Signature'] = signature;
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
const response = await fetch(`${vibeApiUrl}${endpoint}`, {
|
|
65
|
-
method: 'GET',
|
|
66
|
-
headers,
|
|
67
|
-
// 2 second timeout
|
|
68
|
-
signal: AbortSignal.timeout(2000),
|
|
69
|
-
});
|
|
70
|
-
if (!response.ok) {
|
|
71
|
-
console.warn('[JWT_CALLBACK] Failed to fetch Vibe roles:', response.status);
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
const data = await response.json();
|
|
75
|
-
const roles = data.roles?.map((r) => r.role_name || r) || [];
|
|
76
|
-
console.log('[JWT_CALLBACK] Fetched Vibe roles:', roles);
|
|
77
|
-
return roles;
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
console.warn('[JWT_CALLBACK] Error fetching Vibe roles (continuing with IDP roles only):', error);
|
|
81
|
-
return [];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Merge IDP roles with Vibe roles, deduplicating.
|
|
86
|
-
*/
|
|
87
|
-
function mergeRoles(idpRoles, vibeRoles) {
|
|
88
|
-
return [...new Set([...idpRoles, ...vibeRoles])];
|
|
89
|
-
}
|
|
90
|
-
// ============================================================================
|
|
91
|
-
// JWT CALLBACK
|
|
92
|
-
// ============================================================================
|
|
93
|
-
/**
|
|
94
|
-
* JWT callback - builds the NextAuth JWT token.
|
|
95
|
-
*
|
|
96
|
-
* MINIMAL TOKEN STRATEGY:
|
|
97
|
-
* - Only store redisSessionId (key to Redis session)
|
|
98
|
-
* - All tokens and user data live in Redis
|
|
99
|
-
* - Browser cookie stays small and secure
|
|
100
|
-
*
|
|
101
|
-
* @param params - JWT callback parameters from NextAuth
|
|
102
|
-
* @returns JWT payload to store in browser cookie
|
|
103
|
-
*/
|
|
104
|
-
async function jwtCallback({ token, user, account, trigger, }) {
|
|
105
|
-
console.log('[JWT_CALLBACK] Called with:', {
|
|
106
|
-
trigger,
|
|
107
|
-
hasAccount: !!account,
|
|
108
|
-
provider: account?.provider,
|
|
109
|
-
hasUser: !!user,
|
|
110
|
-
userEmail: user?.email,
|
|
111
|
-
existingRedisSessionId: token?.redisSessionId ? 'yes' : 'no',
|
|
112
|
-
});
|
|
113
|
-
// -------------------------------------------------------------------------
|
|
114
|
-
// OAuth Sign-In: Register with IDP and create session
|
|
115
|
-
// -------------------------------------------------------------------------
|
|
116
|
-
if (account && account.provider !== 'credentials') {
|
|
117
|
-
console.log('[JWT_CALLBACK] Handling OAuth sign-in for provider:', account.provider);
|
|
118
|
-
return handleOAuthSignIn(token, user, account);
|
|
119
|
-
}
|
|
120
|
-
// -------------------------------------------------------------------------
|
|
121
|
-
// Credentials Sign-In: Session already created in authorize()
|
|
122
|
-
// -------------------------------------------------------------------------
|
|
123
|
-
if (user && user.redisSessionId) {
|
|
124
|
-
// Credentials authorize() returns redisSessionId
|
|
125
|
-
const redisSessionId = user.redisSessionId;
|
|
126
|
-
return {
|
|
127
|
-
...token,
|
|
128
|
-
redisSessionId,
|
|
129
|
-
sub: user.id || token.sub || 'unknown',
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
// -------------------------------------------------------------------------
|
|
133
|
-
// Subsequent Requests: Validate session exists
|
|
134
|
-
// -------------------------------------------------------------------------
|
|
135
|
-
const redisSessionId = user?.redisSessionId || token?.redisSessionId || token?.redisSessionId;
|
|
136
|
-
if (!redisSessionId) {
|
|
137
|
-
return { ...token, error: 'NoSession', sub: token.sub || 'unknown' };
|
|
138
|
-
}
|
|
139
|
-
// Validate session still exists in Redis
|
|
140
|
-
try {
|
|
141
|
-
const sessionData = await (0, session_store_1.getSession)(redisSessionId);
|
|
142
|
-
if (!sessionData) {
|
|
143
|
-
// Session expired or deleted
|
|
144
|
-
return { ...token, error: 'SessionNotFound', sub: token.sub || 'unknown' };
|
|
145
|
-
}
|
|
146
|
-
// Check if refresh token has expired (session should be terminated)
|
|
147
|
-
if (sessionData.idpRefreshTokenExpires && Date.now() >= sessionData.idpRefreshTokenExpires) {
|
|
148
|
-
return { ...token, error: 'RefreshTokenExpired', sub: token.sub || 'unknown' };
|
|
149
|
-
}
|
|
150
|
-
// Check if MFA has expired (requires step-up authentication)
|
|
151
|
-
if (sessionData.mfaExpiresAt && Date.now() > sessionData.mfaExpiresAt) {
|
|
152
|
-
return {
|
|
153
|
-
...token,
|
|
154
|
-
redisSessionId,
|
|
155
|
-
sub: sessionData.userId,
|
|
156
|
-
error: 'MfaExpired',
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
console.error('[JWT_CALLBACK] Session validation error:', error);
|
|
162
|
-
return { ...token, error: 'SessionError', sub: token.sub || 'unknown' };
|
|
163
|
-
}
|
|
164
|
-
// Session is valid - return minimal token
|
|
165
|
-
return {
|
|
166
|
-
...token,
|
|
167
|
-
redisSessionId,
|
|
168
|
-
sub: token.sub || 'unknown',
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
// ============================================================================
|
|
172
|
-
// OAUTH SIGN-IN HANDLER
|
|
173
|
-
// ============================================================================
|
|
174
|
-
/**
|
|
175
|
-
* Handle OAuth sign-in by registering with IDP and creating session.
|
|
176
|
-
*/
|
|
177
|
-
async function handleOAuthSignIn(token, user, account) {
|
|
178
|
-
console.log('[JWT_CALLBACK] handleOAuthSignIn starting for:', {
|
|
179
|
-
provider: account.provider,
|
|
180
|
-
email: user?.email,
|
|
181
|
-
providerAccountId: account.providerAccountId,
|
|
182
|
-
});
|
|
183
|
-
try {
|
|
184
|
-
// Call IDP to register/authenticate OAuth user
|
|
185
|
-
const idpResult = await (0, idp_client_1.idpOAuthCallback)({
|
|
186
|
-
provider: account.provider,
|
|
187
|
-
providerAccountId: account.providerAccountId,
|
|
188
|
-
email: user?.email || '',
|
|
189
|
-
name: user?.name || '',
|
|
190
|
-
image: user?.image || '',
|
|
191
|
-
accessToken: account.access_token,
|
|
192
|
-
refreshToken: account.refresh_token,
|
|
193
|
-
expiresAt: account.expires_at,
|
|
194
|
-
});
|
|
195
|
-
// Build session data using normalized field names
|
|
196
|
-
let sessionData;
|
|
197
|
-
let mfaVerified = false;
|
|
198
|
-
if (idpResult.success && idpResult.data?.accessToken) {
|
|
199
|
-
// IDP integration succeeded - we have IDP tokens
|
|
200
|
-
const decoded = (0, token_utils_1.decodeIdpAccessToken)(idpResult.data.accessToken);
|
|
201
|
-
const amrClaims = decoded ? (0, token_utils_1.extractAmrFromToken)(decoded) : [];
|
|
202
|
-
const acrLevel = decoded?.acr || '1';
|
|
203
|
-
// Extract kid from JWT header (CRITICAL: different from client_id in payload)
|
|
204
|
-
const bearerKeyId = (0, token_utils_1.extractKidFromToken)(idpResult.data.accessToken);
|
|
205
|
-
if (bearerKeyId) {
|
|
206
|
-
console.log('[JWT_CALLBACK] Extracted bearerKeyId (kid) from JWT header:', bearerKeyId);
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
console.warn('[JWT_CALLBACK] No kid found in JWT header');
|
|
210
|
-
}
|
|
211
|
-
// Check if MFA is required for this client
|
|
212
|
-
try {
|
|
213
|
-
const clientConfig = await (0, idp_client_config_1.getIDPClientConfig)();
|
|
214
|
-
const require2FA = clientConfig?.authSettings?.require2FA ?? true;
|
|
215
|
-
mfaVerified = !require2FA; // If MFA not required, mark as verified
|
|
216
|
-
}
|
|
217
|
-
catch {
|
|
218
|
-
// Default to requiring MFA if config unavailable
|
|
219
|
-
mfaVerified = false;
|
|
220
|
-
}
|
|
221
|
-
sessionData = {
|
|
222
|
-
userId: idpResult.data.user?.userId?.toString() || account.providerAccountId,
|
|
223
|
-
email: idpResult.data.user?.email || user?.email || '',
|
|
224
|
-
name: idpResult.data.user?.fullName || user?.name || '',
|
|
225
|
-
roles: idpResult.data.user?.roles || [],
|
|
226
|
-
// IDP tokens (normalized names)
|
|
227
|
-
idpAccessToken: idpResult.data.accessToken,
|
|
228
|
-
idpRefreshToken: idpResult.data.refreshToken,
|
|
229
|
-
idpAccessTokenExpires: decoded?.exp ? (0, token_utils_1.expClaimToMs)(decoded.exp) : Date.now() + 3600000,
|
|
230
|
-
decodedAccessToken: decoded || undefined,
|
|
231
|
-
// Bearer key ID from JWT header (NOT client_id from payload)
|
|
232
|
-
bearerKeyId,
|
|
233
|
-
// MFA state (normalized names)
|
|
234
|
-
mfaVerified,
|
|
235
|
-
authenticationMethods: amrClaims,
|
|
236
|
-
authenticationLevel: acrLevel,
|
|
237
|
-
// OAuth provider info (normalized names)
|
|
238
|
-
oauthProvider: account.provider,
|
|
239
|
-
oauthProviderToken: account.access_token,
|
|
240
|
-
oauthProviderRefreshToken: account.refresh_token,
|
|
241
|
-
// Multi-tenant info
|
|
242
|
-
idpClientId: decoded?.client_id,
|
|
243
|
-
merchantId: decoded?.merchant_id,
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
// IDP integration failed - create OAuth-only session
|
|
248
|
-
// This allows OAuth login to work even if IDP is unavailable
|
|
249
|
-
mfaVerified = true; // OAuth IS multi-factor (Google/Microsoft handle MFA)
|
|
250
|
-
sessionData = {
|
|
251
|
-
userId: account.providerAccountId,
|
|
252
|
-
email: user?.email || '',
|
|
253
|
-
name: user?.name || '',
|
|
254
|
-
roles: [],
|
|
255
|
-
mfaVerified: true, // OAuth IS multi-factor
|
|
256
|
-
oauthProvider: account.provider,
|
|
257
|
-
oauthProviderToken: account.access_token,
|
|
258
|
-
oauthProviderRefreshToken: account.refresh_token,
|
|
259
|
-
idpAccessTokenExpires: account.expires_at
|
|
260
|
-
? account.expires_at * 1000
|
|
261
|
-
: Date.now() + 3600000,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
// -------------------------------------------------------------------------
|
|
265
|
-
// ROLE MERGING: Fetch Vibe roles and merge with IDP roles
|
|
266
|
-
// -------------------------------------------------------------------------
|
|
267
|
-
const clientId = sessionData.idpClientId || process.env.IDP_CLIENT_ID || '';
|
|
268
|
-
if (clientId && sessionData.userId) {
|
|
269
|
-
const vibeRoles = await fetchVibeRoles(sessionData.userId, clientId);
|
|
270
|
-
// SECURITY: Filter out protected IDP-level role prefixes to prevent injection
|
|
271
|
-
const safeVibeRoles = vibeRoles.filter(r => !r.startsWith('payez_'));
|
|
272
|
-
const idpRoles = sessionData.roles || [];
|
|
273
|
-
sessionData.roles = mergeRoles(idpRoles, safeVibeRoles);
|
|
274
|
-
console.log('[JWT_CALLBACK] Merged roles:', {
|
|
275
|
-
idpRoles,
|
|
276
|
-
vibeRoles,
|
|
277
|
-
safeVibeRoles,
|
|
278
|
-
merged: sessionData.roles,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
// Create Redis session
|
|
282
|
-
console.log('[JWT_CALLBACK] Creating Redis session for:', {
|
|
283
|
-
userId: sessionData.userId,
|
|
284
|
-
email: sessionData.email,
|
|
285
|
-
mfaVerified: sessionData.mfaVerified,
|
|
286
|
-
roles: sessionData.roles,
|
|
287
|
-
});
|
|
288
|
-
const redisSessionId = await (0, session_store_1.createSession)(sessionData);
|
|
289
|
-
console.log('[JWT_CALLBACK] Redis session created:', {
|
|
290
|
-
redisSessionId: redisSessionId ? redisSessionId.substring(0, 8) + '...' : 'NONE',
|
|
291
|
-
});
|
|
292
|
-
// Check if immediate MFA redirect is needed
|
|
293
|
-
const needsImmediateTwoFactor = !mfaVerified;
|
|
294
|
-
return {
|
|
295
|
-
...token,
|
|
296
|
-
redisSessionId,
|
|
297
|
-
sub: sessionData.userId,
|
|
298
|
-
requiresTwoFactorRedirect: needsImmediateTwoFactor,
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
catch (error) {
|
|
302
|
-
console.error('[JWT_CALLBACK] handleOAuthSignIn FAILED:', error);
|
|
303
|
-
return { ...token, error: 'OAuthSignInFailed', sub: token.sub || 'unknown' };
|
|
304
|
-
}
|
|
305
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session Callback
|
|
3
|
-
*
|
|
4
|
-
* Builds the NextAuth session from Redis session data.
|
|
5
|
-
* The JWT only contains redisSessionId - all user data comes from Redis.
|
|
6
|
-
*
|
|
7
|
-
* FLOW:
|
|
8
|
-
* 1. Extract redisSessionId from JWT token
|
|
9
|
-
* 2. Fetch session data from Redis
|
|
10
|
-
* 3. Build NextAuth session with user info
|
|
11
|
-
*
|
|
12
|
-
* @version 1.0.0
|
|
13
|
-
* @since auth-refactor-2026-01
|
|
14
|
-
*/
|
|
15
|
-
import type { Session } from 'next-auth';
|
|
16
|
-
import type { JWT } from 'next-auth/jwt';
|
|
17
|
-
interface SessionCallbackParams {
|
|
18
|
-
session: Session;
|
|
19
|
-
token: JWT & {
|
|
20
|
-
/** Redis session ID - the key to look up session data */
|
|
21
|
-
redisSessionId?: string;
|
|
22
|
-
error?: string;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
interface AppSessionUser {
|
|
26
|
-
id: string;
|
|
27
|
-
email: string;
|
|
28
|
-
name?: string;
|
|
29
|
-
roles: string[];
|
|
30
|
-
twoFactorSessionVerified: boolean;
|
|
31
|
-
requiresTwoFactor: boolean;
|
|
32
|
-
authenticationMethods?: string[];
|
|
33
|
-
authenticationLevel?: string;
|
|
34
|
-
mfaCompletedAt?: number;
|
|
35
|
-
mfaExpiresAt?: number;
|
|
36
|
-
mfaValidityHours?: number;
|
|
37
|
-
oauthProvider?: string;
|
|
38
|
-
idpClientId?: string;
|
|
39
|
-
merchantId?: string;
|
|
40
|
-
bearerKeyId?: string;
|
|
41
|
-
}
|
|
42
|
-
interface AppSession extends Omit<Session, 'user'> {
|
|
43
|
-
user: AppSessionUser;
|
|
44
|
-
sessionToken?: string;
|
|
45
|
-
accessToken?: string;
|
|
46
|
-
refreshToken?: string;
|
|
47
|
-
accessTokenExpires?: number;
|
|
48
|
-
error?: string;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Session callback - builds NextAuth session from Redis.
|
|
52
|
-
*
|
|
53
|
-
* This callback is called whenever getSession() or useSession() is used.
|
|
54
|
-
* It fetches the full session from Redis and exposes it to the client.
|
|
55
|
-
*
|
|
56
|
-
* @param params - Session callback parameters from NextAuth
|
|
57
|
-
* @returns AppSession with user data from Redis
|
|
58
|
-
*/
|
|
59
|
-
export declare function sessionCallback({ session, token, }: SessionCallbackParams): Promise<AppSession>;
|
|
60
|
-
export {};
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Session Callback
|
|
4
|
-
*
|
|
5
|
-
* Builds the NextAuth session from Redis session data.
|
|
6
|
-
* The JWT only contains redisSessionId - all user data comes from Redis.
|
|
7
|
-
*
|
|
8
|
-
* FLOW:
|
|
9
|
-
* 1. Extract redisSessionId from JWT token
|
|
10
|
-
* 2. Fetch session data from Redis
|
|
11
|
-
* 3. Build NextAuth session with user info
|
|
12
|
-
*
|
|
13
|
-
* @version 1.0.0
|
|
14
|
-
* @since auth-refactor-2026-01
|
|
15
|
-
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.sessionCallback = sessionCallback;
|
|
18
|
-
const session_store_1 = require("../../lib/session-store");
|
|
19
|
-
// ============================================================================
|
|
20
|
-
// SESSION CALLBACK
|
|
21
|
-
// ============================================================================
|
|
22
|
-
/**
|
|
23
|
-
* Session callback - builds NextAuth session from Redis.
|
|
24
|
-
*
|
|
25
|
-
* This callback is called whenever getSession() or useSession() is used.
|
|
26
|
-
* It fetches the full session from Redis and exposes it to the client.
|
|
27
|
-
*
|
|
28
|
-
* @param params - Session callback parameters from NextAuth
|
|
29
|
-
* @returns AppSession with user data from Redis
|
|
30
|
-
*/
|
|
31
|
-
async function sessionCallback({ session, token, }) {
|
|
32
|
-
// Support both field names: sessionToken (auth.ts JWT) and redisSessionId (legacy)
|
|
33
|
-
const redisSessionId = token?.sessionToken || token?.redisSessionId;
|
|
34
|
-
console.log('[SESSION_CALLBACK] Entry:', {
|
|
35
|
-
hasToken: !!token,
|
|
36
|
-
redisSessionId: redisSessionId || 'MISSING',
|
|
37
|
-
tokenError: token?.error || 'none',
|
|
38
|
-
tokenKeys: token ? Object.keys(token) : [],
|
|
39
|
-
});
|
|
40
|
-
// -------------------------------------------------------------------------
|
|
41
|
-
// Handle Token Errors
|
|
42
|
-
// -------------------------------------------------------------------------
|
|
43
|
-
if (token.error) {
|
|
44
|
-
console.log('[SESSION_CALLBACK] Token has error:', token.error);
|
|
45
|
-
// Special case: MFA expired - return partial session for step-up flow
|
|
46
|
-
if (token.error === 'MfaExpired' && redisSessionId) {
|
|
47
|
-
const sessionData = await safeGetSession(redisSessionId);
|
|
48
|
-
if (sessionData) {
|
|
49
|
-
return {
|
|
50
|
-
...session,
|
|
51
|
-
user: {
|
|
52
|
-
id: sessionData.userId,
|
|
53
|
-
email: sessionData.email,
|
|
54
|
-
name: sessionData.name,
|
|
55
|
-
roles: sessionData.roles || [],
|
|
56
|
-
twoFactorSessionVerified: false,
|
|
57
|
-
requiresTwoFactor: true,
|
|
58
|
-
authenticationMethods: sessionData.authenticationMethods,
|
|
59
|
-
authenticationLevel: sessionData.authenticationLevel,
|
|
60
|
-
mfaExpiresAt: sessionData.mfaExpiresAt,
|
|
61
|
-
},
|
|
62
|
-
sessionToken: redisSessionId,
|
|
63
|
-
accessToken: sessionData.idpAccessToken,
|
|
64
|
-
refreshToken: sessionData.idpRefreshToken,
|
|
65
|
-
error: 'MfaExpired',
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// For other errors, try to recover session data if possible
|
|
70
|
-
if (redisSessionId) {
|
|
71
|
-
const sessionData = await safeGetSession(redisSessionId);
|
|
72
|
-
if (sessionData) {
|
|
73
|
-
return buildSessionFromRedis(session, redisSessionId, sessionData);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// No recovery possible - return error session
|
|
77
|
-
return buildErrorSession(session, token.error);
|
|
78
|
-
}
|
|
79
|
-
// -------------------------------------------------------------------------
|
|
80
|
-
// Validate Session Token
|
|
81
|
-
// -------------------------------------------------------------------------
|
|
82
|
-
if (!redisSessionId) {
|
|
83
|
-
console.log('[SESSION_CALLBACK] No redisSessionId - returning error session');
|
|
84
|
-
return buildErrorSession(session, 'NoSessionToken');
|
|
85
|
-
}
|
|
86
|
-
// -------------------------------------------------------------------------
|
|
87
|
-
// Fetch Session from Redis
|
|
88
|
-
// -------------------------------------------------------------------------
|
|
89
|
-
const sessionData = await safeGetSession(redisSessionId);
|
|
90
|
-
if (!sessionData) {
|
|
91
|
-
console.log('[SESSION_CALLBACK] Redis session not found for:', redisSessionId);
|
|
92
|
-
return buildErrorSession(session, 'SessionNotFound');
|
|
93
|
-
}
|
|
94
|
-
console.log('[SESSION_CALLBACK] Redis session found:', {
|
|
95
|
-
userId: sessionData.userId,
|
|
96
|
-
email: sessionData.email,
|
|
97
|
-
roles: sessionData.roles,
|
|
98
|
-
hasAccessToken: !!sessionData.idpAccessToken,
|
|
99
|
-
});
|
|
100
|
-
const result = buildSessionFromRedis(session, redisSessionId, sessionData);
|
|
101
|
-
console.log('[SESSION_CALLBACK] Returning:', {
|
|
102
|
-
userId: result.user.id,
|
|
103
|
-
roles: result.user.roles,
|
|
104
|
-
hasAccessToken: !!result.accessToken,
|
|
105
|
-
});
|
|
106
|
-
return result;
|
|
107
|
-
}
|
|
108
|
-
// ============================================================================
|
|
109
|
-
// HELPER FUNCTIONS
|
|
110
|
-
// ============================================================================
|
|
111
|
-
/**
|
|
112
|
-
* Safely fetch session from Redis, returning null on error.
|
|
113
|
-
*/
|
|
114
|
-
async function safeGetSession(sessionId) {
|
|
115
|
-
try {
|
|
116
|
-
return await (0, session_store_1.getSession)(sessionId);
|
|
117
|
-
}
|
|
118
|
-
catch {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Build complete session from Redis data.
|
|
124
|
-
* Uses normalized field names from SessionData.
|
|
125
|
-
*/
|
|
126
|
-
function buildSessionFromRedis(session, sessionId, data) {
|
|
127
|
-
return {
|
|
128
|
-
...session,
|
|
129
|
-
user: {
|
|
130
|
-
id: data.userId,
|
|
131
|
-
email: data.email,
|
|
132
|
-
name: data.name,
|
|
133
|
-
roles: data.roles || [],
|
|
134
|
-
// MFA state (normalized field name)
|
|
135
|
-
twoFactorSessionVerified: data.mfaVerified,
|
|
136
|
-
requiresTwoFactor: !data.mfaVerified,
|
|
137
|
-
authenticationMethods: data.authenticationMethods,
|
|
138
|
-
authenticationLevel: data.authenticationLevel,
|
|
139
|
-
mfaCompletedAt: data.mfaCompletedAt,
|
|
140
|
-
mfaExpiresAt: data.mfaExpiresAt,
|
|
141
|
-
mfaValidityHours: data.mfaValidityHours,
|
|
142
|
-
oauthProvider: data.oauthProvider,
|
|
143
|
-
idpClientId: data.idpClientId,
|
|
144
|
-
merchantId: data.merchantId,
|
|
145
|
-
// Bearer key ID from JWT header (may be undefined for old sessions)
|
|
146
|
-
bearerKeyId: data.bearerKeyId,
|
|
147
|
-
},
|
|
148
|
-
sessionToken: sessionId,
|
|
149
|
-
// IDP tokens (normalized field names)
|
|
150
|
-
accessToken: data.idpAccessToken,
|
|
151
|
-
refreshToken: data.idpRefreshToken,
|
|
152
|
-
accessTokenExpires: data.idpAccessTokenExpires,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Build error session with empty user.
|
|
157
|
-
*/
|
|
158
|
-
function buildErrorSession(session, error) {
|
|
159
|
-
return {
|
|
160
|
-
...session,
|
|
161
|
-
user: {
|
|
162
|
-
id: '',
|
|
163
|
-
email: '',
|
|
164
|
-
roles: [],
|
|
165
|
-
twoFactorSessionVerified: false,
|
|
166
|
-
requiresTwoFactor: false,
|
|
167
|
-
},
|
|
168
|
-
error,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SignIn Callback
|
|
3
|
-
*
|
|
4
|
-
* Handles post-authentication actions like 2FA redirect.
|
|
5
|
-
* Called after credentials or OAuth authentication succeeds.
|
|
6
|
-
*
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
* @since auth-refactor-2026-01
|
|
9
|
-
*/
|
|
10
|
-
import type { User, Account } from 'next-auth';
|
|
11
|
-
/**
|
|
12
|
-
* SignIn callback - handle 2FA redirect for OAuth users.
|
|
13
|
-
*
|
|
14
|
-
* When require2FA is true for the client, OAuth users need to be
|
|
15
|
-
* redirected to the verify-code page immediately after OAuth login.
|
|
16
|
-
*
|
|
17
|
-
* @param params - SignIn callback parameters from NextAuth
|
|
18
|
-
* @returns true to allow sign-in, or a URL string to redirect
|
|
19
|
-
*/
|
|
20
|
-
export declare function signInCallback({ user, account, }: {
|
|
21
|
-
user: User | any;
|
|
22
|
-
account: Account | null;
|
|
23
|
-
}): Promise<boolean | string>;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* SignIn Callback
|
|
4
|
-
*
|
|
5
|
-
* Handles post-authentication actions like 2FA redirect.
|
|
6
|
-
* Called after credentials or OAuth authentication succeeds.
|
|
7
|
-
*
|
|
8
|
-
* @version 1.0.0
|
|
9
|
-
* @since auth-refactor-2026-01
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.signInCallback = signInCallback;
|
|
13
|
-
// ============================================================================
|
|
14
|
-
// SIGNIN CALLBACK
|
|
15
|
-
// ============================================================================
|
|
16
|
-
/**
|
|
17
|
-
* SignIn callback - handle 2FA redirect for OAuth users.
|
|
18
|
-
*
|
|
19
|
-
* When require2FA is true for the client, OAuth users need to be
|
|
20
|
-
* redirected to the verify-code page immediately after OAuth login.
|
|
21
|
-
*
|
|
22
|
-
* @param params - SignIn callback parameters from NextAuth
|
|
23
|
-
* @returns true to allow sign-in, or a URL string to redirect
|
|
24
|
-
*/
|
|
25
|
-
async function signInCallback({ user, account, }) {
|
|
26
|
-
// Only handle OAuth providers (credentials flow handles 2FA separately)
|
|
27
|
-
if (!account?.provider || account.provider === 'credentials') {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
// Check if OAuth user needs 2FA redirect
|
|
31
|
-
const token = user;
|
|
32
|
-
if (token?.requiresTwoFactorRedirect) {
|
|
33
|
-
// Preserve the original callback URL through 2FA flow
|
|
34
|
-
const originalCallbackUrl = account?.callbackUrl || '/';
|
|
35
|
-
// Don't redirect back to auth pages after 2FA
|
|
36
|
-
const safeCallbackUrl = originalCallbackUrl.startsWith('/account-auth/')
|
|
37
|
-
? '/'
|
|
38
|
-
: originalCallbackUrl;
|
|
39
|
-
const encodedCallback = encodeURIComponent(safeCallbackUrl);
|
|
40
|
-
// Return redirect URL - NextAuth will redirect here instead of completing sign-in
|
|
41
|
-
return `/account-auth/verify-code?callbackUrl=${encodedCallback}`;
|
|
42
|
-
}
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Auth Events - Public Exports
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.handleSignOut = void 0;
|
|
7
|
-
var signout_1 = require("./signout");
|
|
8
|
-
Object.defineProperty(exports, "handleSignOut", { enumerable: true, get: function () { return signout_1.handleSignOut; } });
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SignOut Event Handler
|
|
3
|
-
*
|
|
4
|
-
* Cleans up Redis session when user signs out.
|
|
5
|
-
*
|
|
6
|
-
* @version 1.0.0
|
|
7
|
-
* @since auth-refactor-2026-01
|
|
8
|
-
*/
|
|
9
|
-
import type { JWT } from 'next-auth/jwt';
|
|
10
|
-
/**
|
|
11
|
-
* Handle user sign out by deleting Redis session.
|
|
12
|
-
*
|
|
13
|
-
* @param token - The JWT token containing the session ID
|
|
14
|
-
*/
|
|
15
|
-
export declare function handleSignOut({ token }: {
|
|
16
|
-
token: JWT | null;
|
|
17
|
-
}): Promise<void>;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* SignOut Event Handler
|
|
4
|
-
*
|
|
5
|
-
* Cleans up Redis session when user signs out.
|
|
6
|
-
*
|
|
7
|
-
* @version 1.0.0
|
|
8
|
-
* @since auth-refactor-2026-01
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.handleSignOut = handleSignOut;
|
|
12
|
-
const session_store_1 = require("../../lib/session-store");
|
|
13
|
-
// ============================================================================
|
|
14
|
-
// SIGNOUT EVENT
|
|
15
|
-
// ============================================================================
|
|
16
|
-
/**
|
|
17
|
-
* Handle user sign out by deleting Redis session.
|
|
18
|
-
*
|
|
19
|
-
* @param token - The JWT token containing the session ID
|
|
20
|
-
*/
|
|
21
|
-
async function handleSignOut({ token }) {
|
|
22
|
-
// Support both field names: sessionToken (auth.ts JWT) and redisSessionId (legacy)
|
|
23
|
-
const redisSessionId = token?.sessionToken || token?.redisSessionId;
|
|
24
|
-
if (redisSessionId) {
|
|
25
|
-
try {
|
|
26
|
-
await (0, session_store_1.deleteSession)(redisSessionId);
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error('[SIGNOUT_EVENT] Failed to delete session:', error);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|