@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,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Slim Middleware — Cookie-Only Auth Check
|
|
4
|
-
*
|
|
5
|
-
* Replaces the self-fetching middleware with a cookie existence check.
|
|
6
|
-
* All real auth validation happens in server-side layouts (authGuard).
|
|
7
|
-
*
|
|
8
|
-
* Zero self-fetches. Zero Redis calls. Zero JWT decoding.
|
|
9
|
-
* Just: does the session cookie exist? Yes → pass through. No → redirect to login.
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createSlimMiddleware = createSlimMiddleware;
|
|
13
|
-
const server_1 = require("next/server");
|
|
14
|
-
const app_slug_1 = require("../lib/app-slug");
|
|
15
|
-
// =============================================================================
|
|
16
|
-
// DEFAULT BYPASS PATHS
|
|
17
|
-
// =============================================================================
|
|
18
|
-
/** Routes that must always bypass middleware (prevent infinite loops) */
|
|
19
|
-
const DEFAULT_BYPASS_PREFIXES = [
|
|
20
|
-
'/api/auth/',
|
|
21
|
-
'/api/session/',
|
|
22
|
-
'/_next/',
|
|
23
|
-
'/favicon.ico',
|
|
24
|
-
];
|
|
25
|
-
/** Static file extensions to bypass */
|
|
26
|
-
const STATIC_EXTENSIONS = /\.(svg|png|jpg|jpeg|gif|webp|ico|css|js|woff|woff2|ttf|eot|map)$/i;
|
|
27
|
-
// =============================================================================
|
|
28
|
-
// MAIN
|
|
29
|
-
// =============================================================================
|
|
30
|
-
/**
|
|
31
|
-
* Create a slim middleware that only checks cookie existence.
|
|
32
|
-
* Auth validation is deferred to server-side layouts (authGuard).
|
|
33
|
-
*/
|
|
34
|
-
function createSlimMiddleware(options) {
|
|
35
|
-
const publicRoutes = options?.publicRoutes || [];
|
|
36
|
-
const loginUrl = options?.loginUrl || '/account-auth/login';
|
|
37
|
-
const extraBypass = options?.bypassPrefixes || [];
|
|
38
|
-
const allBypass = [...DEFAULT_BYPASS_PREFIXES, ...extraBypass];
|
|
39
|
-
// Pre-compile public route patterns for fast matching
|
|
40
|
-
const publicMatchers = publicRoutes.map(pattern => {
|
|
41
|
-
if (pattern.endsWith('/*')) {
|
|
42
|
-
const prefix = pattern.slice(0, -2);
|
|
43
|
-
return (p) => p === prefix || p.startsWith(prefix + '/');
|
|
44
|
-
}
|
|
45
|
-
if (pattern.endsWith('*')) {
|
|
46
|
-
const prefix = pattern.slice(0, -1);
|
|
47
|
-
return (p) => p.startsWith(prefix);
|
|
48
|
-
}
|
|
49
|
-
if (pattern.startsWith('/*.')) {
|
|
50
|
-
const ext = pattern.slice(2);
|
|
51
|
-
return (p) => p.endsWith(ext);
|
|
52
|
-
}
|
|
53
|
-
return (p) => p === pattern;
|
|
54
|
-
});
|
|
55
|
-
return function middleware(request) {
|
|
56
|
-
const { pathname } = request.nextUrl;
|
|
57
|
-
// 1. Always bypass static/internal routes
|
|
58
|
-
if (STATIC_EXTENSIONS.test(pathname)) {
|
|
59
|
-
return server_1.NextResponse.next();
|
|
60
|
-
}
|
|
61
|
-
for (const prefix of allBypass) {
|
|
62
|
-
if (pathname.startsWith(prefix)) {
|
|
63
|
-
return server_1.NextResponse.next();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// 2. Check if it's a public route → pass through
|
|
67
|
-
for (const matcher of publicMatchers) {
|
|
68
|
-
if (matcher(pathname)) {
|
|
69
|
-
return server_1.NextResponse.next();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// 3. THE ONLY AUTH CHECK: Does a session cookie exist?
|
|
73
|
-
const sessionCookieName = (0, app_slug_1.getSessionCookieName)();
|
|
74
|
-
const secureCookieName = (0, app_slug_1.getSecureSessionCookieName)();
|
|
75
|
-
const hasCookie = request.cookies.has(sessionCookieName) ||
|
|
76
|
-
request.cookies.has(secureCookieName);
|
|
77
|
-
if (!hasCookie) {
|
|
78
|
-
// No cookie on a protected route → redirect to login
|
|
79
|
-
// API routes get 401 instead of redirect
|
|
80
|
-
if (pathname.startsWith('/api/')) {
|
|
81
|
-
return server_1.NextResponse.json({ error: 'Unauthorized', message: 'No session' }, { status: 401 });
|
|
82
|
-
}
|
|
83
|
-
const callbackUrl = encodeURIComponent(pathname);
|
|
84
|
-
return server_1.NextResponse.redirect(new URL(`${loginUrl}?callbackUrl=${callbackUrl}`, request.url));
|
|
85
|
-
}
|
|
86
|
-
// Cookie exists → pass through, layout authGuard does the real validation
|
|
87
|
-
return server_1.NextResponse.next();
|
|
88
|
-
};
|
|
89
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server-Side Auth Wrapper for API Routes & Server Actions
|
|
3
|
-
*
|
|
4
|
-
* Wraps route handlers with session validation. Uses direct Redis reads.
|
|
5
|
-
* Zero HTTP self-fetches.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* export const GET = withAuth(async (req, auth) => {
|
|
9
|
-
* return NextResponse.json({ userId: auth.userId });
|
|
10
|
-
* });
|
|
11
|
-
*
|
|
12
|
-
* // With role requirement:
|
|
13
|
-
* export const POST = withAuth(async (req, auth) => { ... }, { requiredRoles: ['admin'] });
|
|
14
|
-
*/
|
|
15
|
-
import 'server-only';
|
|
16
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
17
|
-
import type { SessionData } from '../lib/session-store';
|
|
18
|
-
export interface ApiAuthResult {
|
|
19
|
-
userId: string;
|
|
20
|
-
email: string;
|
|
21
|
-
roles: string[];
|
|
22
|
-
sessionData: SessionData;
|
|
23
|
-
accessToken?: string;
|
|
24
|
-
}
|
|
25
|
-
export interface WithAuthOptions {
|
|
26
|
-
/** Roles required to access the route (any match = allowed) */
|
|
27
|
-
requiredRoles?: string[];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Wrap an API route handler with auth validation.
|
|
31
|
-
* Returns 401 if not authenticated, 403 if missing required roles.
|
|
32
|
-
*/
|
|
33
|
-
export declare function withAuth(handler: (req: NextRequest, auth: ApiAuthResult) => Promise<NextResponse>, options?: WithAuthOptions): (req: NextRequest) => Promise<NextResponse>;
|
package/dist/server/with-auth.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Server-Side Auth Wrapper for API Routes & Server Actions
|
|
4
|
-
*
|
|
5
|
-
* Wraps route handlers with session validation. Uses direct Redis reads.
|
|
6
|
-
* Zero HTTP self-fetches.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* export const GET = withAuth(async (req, auth) => {
|
|
10
|
-
* return NextResponse.json({ userId: auth.userId });
|
|
11
|
-
* });
|
|
12
|
-
*
|
|
13
|
-
* // With role requirement:
|
|
14
|
-
* export const POST = withAuth(async (req, auth) => { ... }, { requiredRoles: ['admin'] });
|
|
15
|
-
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.withAuth = withAuth;
|
|
18
|
-
require("server-only");
|
|
19
|
-
const server_1 = require("next/server");
|
|
20
|
-
const decode_session_1 = require("./decode-session");
|
|
21
|
-
// =============================================================================
|
|
22
|
-
// MAIN
|
|
23
|
-
// =============================================================================
|
|
24
|
-
/**
|
|
25
|
-
* Wrap an API route handler with auth validation.
|
|
26
|
-
* Returns 401 if not authenticated, 403 if missing required roles.
|
|
27
|
-
*/
|
|
28
|
-
function withAuth(handler, options) {
|
|
29
|
-
return async (req) => {
|
|
30
|
-
try {
|
|
31
|
-
// Decode session from request cookies (direct Redis, no self-fetch)
|
|
32
|
-
const decoded = await (0, decode_session_1.decodeSession)(req.cookies);
|
|
33
|
-
if (!decoded) {
|
|
34
|
-
return server_1.NextResponse.json({ error: 'Unauthorized', message: 'No valid session' }, { status: 401 });
|
|
35
|
-
}
|
|
36
|
-
const { sessionData } = decoded;
|
|
37
|
-
// Check required roles
|
|
38
|
-
if (options?.requiredRoles && options.requiredRoles.length > 0) {
|
|
39
|
-
const userRoles = sessionData.roles || [];
|
|
40
|
-
const hasRole = options.requiredRoles.some(r => userRoles.includes(r));
|
|
41
|
-
if (!hasRole) {
|
|
42
|
-
return server_1.NextResponse.json({ error: 'Forbidden', message: 'Insufficient permissions' }, { status: 403 });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const auth = {
|
|
46
|
-
userId: sessionData.userId,
|
|
47
|
-
email: sessionData.email,
|
|
48
|
-
roles: sessionData.roles || [],
|
|
49
|
-
sessionData,
|
|
50
|
-
accessToken: sessionData.idpAccessToken,
|
|
51
|
-
};
|
|
52
|
-
return handler(req, auth);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
console.error('[WITH-AUTH] Error:', error instanceof Error ? error.message : String(error));
|
|
56
|
-
return server_1.NextResponse.json({ error: 'Internal Server Error', message: 'Auth check failed' }, { status: 500 });
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export interface HealthStatus {
|
|
2
|
-
isHealthy: boolean;
|
|
3
|
-
message: string;
|
|
4
|
-
lastHeartbeat: Date | null;
|
|
5
|
-
connectionId: string | null | undefined;
|
|
6
|
-
responseTime?: string;
|
|
7
|
-
}
|
|
8
|
-
export type HealthStatusCallback = (status: HealthStatus) => void;
|
|
9
|
-
/**
|
|
10
|
-
* SignalR-based health service following Occam's Razor principle:
|
|
11
|
-
* - If SignalR connection is alive = Service is working
|
|
12
|
-
* - If SignalR connection is dead = Service is not working
|
|
13
|
-
* - No complex orchestration, just connection state monitoring
|
|
14
|
-
*/
|
|
15
|
-
declare class SignalRActivityService {
|
|
16
|
-
private connection;
|
|
17
|
-
private subscribers;
|
|
18
|
-
private currentStatus;
|
|
19
|
-
private heartbeatTimeout;
|
|
20
|
-
private readonly heartbeatTimeoutMs;
|
|
21
|
-
/**
|
|
22
|
-
* Start the health monitoring connection
|
|
23
|
-
* @param idpBaseUrl - The base URL of the IDP server (e.g., 'http://localhost:32785')
|
|
24
|
-
*/
|
|
25
|
-
start(idpBaseUrl: string): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Stop the health monitoring connection
|
|
28
|
-
*/
|
|
29
|
-
stop(): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* Subscribe to health status changes
|
|
32
|
-
*/
|
|
33
|
-
subscribe(callback: HealthStatusCallback): () => void;
|
|
34
|
-
/**
|
|
35
|
-
* Get current health status
|
|
36
|
-
*/
|
|
37
|
-
getCurrentStatus(): HealthStatus;
|
|
38
|
-
private updateStatus;
|
|
39
|
-
private notifySubscribers;
|
|
40
|
-
private resetHeartbeatTimeout;
|
|
41
|
-
private clearHeartbeatTimeout;
|
|
42
|
-
}
|
|
43
|
-
export declare const signalRActivityService: SignalRActivityService;
|
|
44
|
-
export {};
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.signalRActivityService = void 0;
|
|
37
|
-
const signalR = __importStar(require("@microsoft/signalr"));
|
|
38
|
-
/**
|
|
39
|
-
* SignalR-based health service following Occam's Razor principle:
|
|
40
|
-
* - If SignalR connection is alive = Service is working
|
|
41
|
-
* - If SignalR connection is dead = Service is not working
|
|
42
|
-
* - No complex orchestration, just connection state monitoring
|
|
43
|
-
*/
|
|
44
|
-
class SignalRActivityService {
|
|
45
|
-
connection = null;
|
|
46
|
-
subscribers = new Set();
|
|
47
|
-
currentStatus = {
|
|
48
|
-
isHealthy: false,
|
|
49
|
-
message: 'Disconnected',
|
|
50
|
-
lastHeartbeat: null,
|
|
51
|
-
connectionId: null
|
|
52
|
-
};
|
|
53
|
-
heartbeatTimeout = null;
|
|
54
|
-
heartbeatTimeoutMs = 45000; // 45 seconds (server sends every 30s)
|
|
55
|
-
/**
|
|
56
|
-
* Start the health monitoring connection
|
|
57
|
-
* @param idpBaseUrl - The base URL of the IDP server (e.g., 'http://localhost:32785')
|
|
58
|
-
*/
|
|
59
|
-
async start(idpBaseUrl) {
|
|
60
|
-
// If we already have a connected or connecting connection, don't start again
|
|
61
|
-
if (this.connection &&
|
|
62
|
-
(this.connection.state === signalR.HubConnectionState.Connected ||
|
|
63
|
-
this.connection.state === signalR.HubConnectionState.Connecting)) {
|
|
64
|
-
console.info('[SignalRHealth] Connection already active, skipping start');
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
// Stop existing connection if it exists
|
|
68
|
-
if (this.connection) {
|
|
69
|
-
await this.stop();
|
|
70
|
-
}
|
|
71
|
-
try {
|
|
72
|
-
if (!idpBaseUrl) {
|
|
73
|
-
throw new Error('IDP base URL is required for health monitoring');
|
|
74
|
-
}
|
|
75
|
-
// Construct absolute hub URL safely
|
|
76
|
-
const activityHubUrl = new URL('/healthHub', idpBaseUrl).toString();
|
|
77
|
-
console.info('[SignalRHealth] Using hub URL:', activityHubUrl);
|
|
78
|
-
this.connection = new signalR.HubConnectionBuilder()
|
|
79
|
-
.withUrl(activityHubUrl, {
|
|
80
|
-
withCredentials: false,
|
|
81
|
-
transport: signalR.HttpTransportType.WebSockets | signalR.HttpTransportType.ServerSentEvents | signalR.HttpTransportType.LongPolling,
|
|
82
|
-
})
|
|
83
|
-
.withAutomaticReconnect({
|
|
84
|
-
nextRetryDelayInMilliseconds: (retryContext) => {
|
|
85
|
-
// More conservative backoff: 5s, 15s, 45s, then stop trying
|
|
86
|
-
const delays = [5000, 15000, 45000];
|
|
87
|
-
if (retryContext.previousRetryCount >= delays.length) {
|
|
88
|
-
return null; // Stop automatic reconnection
|
|
89
|
-
}
|
|
90
|
-
return delays[retryContext.previousRetryCount];
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
.configureLogging(signalR.LogLevel.Critical) // Only critical errors, hide connection noise
|
|
94
|
-
.build();
|
|
95
|
-
// Handle connection events
|
|
96
|
-
this.connection.onclose(() => {
|
|
97
|
-
this.updateStatus({
|
|
98
|
-
isHealthy: false,
|
|
99
|
-
message: 'Service unavailable',
|
|
100
|
-
lastHeartbeat: null,
|
|
101
|
-
connectionId: null
|
|
102
|
-
});
|
|
103
|
-
this.clearHeartbeatTimeout();
|
|
104
|
-
});
|
|
105
|
-
this.connection.onreconnecting(() => {
|
|
106
|
-
this.updateStatus({
|
|
107
|
-
isHealthy: false,
|
|
108
|
-
message: 'Service unavailable',
|
|
109
|
-
lastHeartbeat: this.currentStatus.lastHeartbeat,
|
|
110
|
-
connectionId: null
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
this.connection.onreconnected((connectionId) => {
|
|
114
|
-
this.updateStatus({
|
|
115
|
-
isHealthy: true,
|
|
116
|
-
message: 'Service operational',
|
|
117
|
-
lastHeartbeat: new Date(),
|
|
118
|
-
connectionId
|
|
119
|
-
});
|
|
120
|
-
this.resetHeartbeatTimeout();
|
|
121
|
-
});
|
|
122
|
-
// Handle heartbeat messages - this is the core health indicator
|
|
123
|
-
this.connection.on('Heartbeat', (data) => {
|
|
124
|
-
this.updateStatus({
|
|
125
|
-
isHealthy: true,
|
|
126
|
-
message: 'Service operational',
|
|
127
|
-
lastHeartbeat: new Date(),
|
|
128
|
-
connectionId: this.connection?.connectionId || null
|
|
129
|
-
});
|
|
130
|
-
this.resetHeartbeatTimeout();
|
|
131
|
-
});
|
|
132
|
-
// Handle initial health status
|
|
133
|
-
this.connection.on('HealthStatus', (data) => {
|
|
134
|
-
this.updateStatus({
|
|
135
|
-
isHealthy: data.status === 'healthy',
|
|
136
|
-
message: data.message || 'Service connected',
|
|
137
|
-
lastHeartbeat: new Date(),
|
|
138
|
-
connectionId: this.connection?.connectionId || null
|
|
139
|
-
});
|
|
140
|
-
this.resetHeartbeatTimeout();
|
|
141
|
-
});
|
|
142
|
-
// Start the connection
|
|
143
|
-
await this.connection.start();
|
|
144
|
-
console.info('[SignalRHealth] Connection started, connectionId:', this.connection.connectionId);
|
|
145
|
-
this.updateStatus({
|
|
146
|
-
isHealthy: true,
|
|
147
|
-
message: 'Service connected',
|
|
148
|
-
lastHeartbeat: new Date(),
|
|
149
|
-
connectionId: this.connection.connectionId
|
|
150
|
-
});
|
|
151
|
-
this.resetHeartbeatTimeout();
|
|
152
|
-
}
|
|
153
|
-
catch (error) {
|
|
154
|
-
// Reduce console noise for expected connection failures
|
|
155
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
156
|
-
console.warn('[SignalRHealth] Connection start failed:', errorMessage);
|
|
157
|
-
const isConnectionRefused = errorMessage.includes('ERR_CONNECTION_REFUSED') ||
|
|
158
|
-
errorMessage.includes('Failed to fetch') ||
|
|
159
|
-
errorMessage.includes('Failed to complete negotiation');
|
|
160
|
-
if (isConnectionRefused) {
|
|
161
|
-
// Service is down - this is expected, log at info level
|
|
162
|
-
console.info('SignalR Health Service: Backend service unavailable');
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
// Unexpected error - log as error
|
|
166
|
-
console.error('SignalR Health Service failed to start:', error);
|
|
167
|
-
}
|
|
168
|
-
this.updateStatus({
|
|
169
|
-
isHealthy: false,
|
|
170
|
-
message: 'Service unavailable',
|
|
171
|
-
lastHeartbeat: null,
|
|
172
|
-
connectionId: null
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Stop the health monitoring connection
|
|
178
|
-
*/
|
|
179
|
-
async stop() {
|
|
180
|
-
this.clearHeartbeatTimeout();
|
|
181
|
-
if (this.connection) {
|
|
182
|
-
try {
|
|
183
|
-
// Check if connection is in a state that can be stopped
|
|
184
|
-
if (this.connection.state !== signalR.HubConnectionState.Disconnected) {
|
|
185
|
-
await this.connection.stop();
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
// Ignore "connection was stopped before the hub handshake could complete" errors
|
|
190
|
-
// as these are expected during rapid start/stop cycles
|
|
191
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
192
|
-
if (!errorMessage.includes('stopped before the hub handshake could complete')) {
|
|
193
|
-
console.error('Error stopping SignalR health connection:', error);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
this.connection = null;
|
|
197
|
-
}
|
|
198
|
-
this.updateStatus({
|
|
199
|
-
isHealthy: false,
|
|
200
|
-
message: 'Disconnected',
|
|
201
|
-
lastHeartbeat: null,
|
|
202
|
-
connectionId: null
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Subscribe to health status changes
|
|
207
|
-
*/
|
|
208
|
-
subscribe(callback) {
|
|
209
|
-
this.subscribers.add(callback);
|
|
210
|
-
// Immediately notify with current status
|
|
211
|
-
callback(this.currentStatus);
|
|
212
|
-
// Return unsubscribe function
|
|
213
|
-
return () => {
|
|
214
|
-
this.subscribers.delete(callback);
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Get current health status
|
|
219
|
-
*/
|
|
220
|
-
getCurrentStatus() {
|
|
221
|
-
return { ...this.currentStatus };
|
|
222
|
-
}
|
|
223
|
-
updateStatus(newStatus) {
|
|
224
|
-
this.currentStatus = newStatus;
|
|
225
|
-
this.notifySubscribers();
|
|
226
|
-
}
|
|
227
|
-
notifySubscribers() {
|
|
228
|
-
this.subscribers.forEach(callback => {
|
|
229
|
-
try {
|
|
230
|
-
callback(this.currentStatus);
|
|
231
|
-
}
|
|
232
|
-
catch (error) {
|
|
233
|
-
console.error('Error in health status subscriber:', error);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
resetHeartbeatTimeout() {
|
|
238
|
-
this.clearHeartbeatTimeout();
|
|
239
|
-
// If we don't receive a heartbeat within the timeout period, consider service unhealthy
|
|
240
|
-
this.heartbeatTimeout = setTimeout(() => {
|
|
241
|
-
this.updateStatus({
|
|
242
|
-
isHealthy: false,
|
|
243
|
-
message: 'Service unavailable',
|
|
244
|
-
lastHeartbeat: this.currentStatus.lastHeartbeat,
|
|
245
|
-
connectionId: this.currentStatus.connectionId
|
|
246
|
-
});
|
|
247
|
-
}, this.heartbeatTimeoutMs);
|
|
248
|
-
}
|
|
249
|
-
clearHeartbeatTimeout() {
|
|
250
|
-
if (this.heartbeatTimeout) {
|
|
251
|
-
clearTimeout(this.heartbeatTimeout);
|
|
252
|
-
this.heartbeatTimeout = null;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
// Export singleton instance
|
|
257
|
-
exports.signalRActivityService = new SignalRActivityService();
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 🚀 CENTRALIZED AUTH STORE - THE SINGLE SOURCE OF TRUTH
|
|
3
|
-
*
|
|
4
|
-
* This Zustand store replaces ALL scattered useState patterns for auth-related state.
|
|
5
|
-
* No more prop drilling, no more duplicate loading states, no more auth chaos.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Centralized session, token, and user state
|
|
9
|
-
* - Built-in API calling with auto token refresh
|
|
10
|
-
* - Loading state management for all async operations
|
|
11
|
-
* - Type-safe throughout
|
|
12
|
-
* - Integrates seamlessly with existing NextAuth
|
|
13
|
-
*/
|
|
14
|
-
import { AppSession } from '../lib/session';
|
|
15
|
-
import { HubConnection, HubConnectionState } from '@microsoft/signalr';
|
|
16
|
-
export interface User {
|
|
17
|
-
id: string;
|
|
18
|
-
email: string;
|
|
19
|
-
roles: string[];
|
|
20
|
-
twoFactorSessionVerified: boolean;
|
|
21
|
-
requiresTwoFactor: boolean;
|
|
22
|
-
twoFactorMethod?: string;
|
|
23
|
-
authenticationMethods?: string[];
|
|
24
|
-
authenticationLevel?: string;
|
|
25
|
-
isApproved: boolean;
|
|
26
|
-
isSuspended: boolean;
|
|
27
|
-
lockoutEnabled: boolean;
|
|
28
|
-
lockoutEnd?: Date | null;
|
|
29
|
-
pausedAt?: Date | null;
|
|
30
|
-
pausedBy?: string | null;
|
|
31
|
-
suspensionReason?: string | null;
|
|
32
|
-
}
|
|
33
|
-
export interface UserStateChangeEvent {
|
|
34
|
-
userId: string;
|
|
35
|
-
action: 'APPROVE' | 'DISAPPROVE' | 'PAUSE' | 'RESUME' | 'HALT' | 'UNLOCK';
|
|
36
|
-
newState: {
|
|
37
|
-
isApproved?: boolean;
|
|
38
|
-
isSuspended?: boolean;
|
|
39
|
-
lockoutEnabled?: boolean;
|
|
40
|
-
lockoutEnd?: string | null;
|
|
41
|
-
pausedAt?: string | null;
|
|
42
|
-
pausedBy?: string | null;
|
|
43
|
-
suspensionReason?: string | null;
|
|
44
|
-
};
|
|
45
|
-
reason?: string;
|
|
46
|
-
changedBy: string;
|
|
47
|
-
timestamp: string;
|
|
48
|
-
}
|
|
49
|
-
export interface SecurityNotificationEvent {
|
|
50
|
-
type: 'USER_LOCKOUT' | 'IP_THROTTLE' | 'BRUTE_FORCE' | 'DISTRIBUTED_ATTACK';
|
|
51
|
-
userId?: string;
|
|
52
|
-
ipAddress?: string;
|
|
53
|
-
message: string;
|
|
54
|
-
severity: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
|
|
55
|
-
timestamp: string;
|
|
56
|
-
}
|
|
57
|
-
export interface AuthState {
|
|
58
|
-
session: AppSession | null;
|
|
59
|
-
user: User | null;
|
|
60
|
-
accessToken: string | null;
|
|
61
|
-
refreshToken: string | null;
|
|
62
|
-
isAuthenticated: boolean;
|
|
63
|
-
isInitialized: boolean;
|
|
64
|
-
isLoading: boolean;
|
|
65
|
-
isRefreshingToken: boolean;
|
|
66
|
-
isLoadingUserStats: boolean;
|
|
67
|
-
isLoadingClients: boolean;
|
|
68
|
-
isLoadingRoles: boolean;
|
|
69
|
-
isLoadingUsers: boolean;
|
|
70
|
-
isLoadingUserDetails: Record<string, boolean>;
|
|
71
|
-
isLoadingRoleCategories: boolean;
|
|
72
|
-
isLoadingUserAssignments: Record<string, boolean>;
|
|
73
|
-
isLoadingClientAuthorizations: Record<string, boolean>;
|
|
74
|
-
error: string | null;
|
|
75
|
-
tokenError: string | null;
|
|
76
|
-
userStats: any | null;
|
|
77
|
-
clients: any[] | null;
|
|
78
|
-
roles: any[] | null;
|
|
79
|
-
users: any[] | null;
|
|
80
|
-
userDetails: Record<string, any>;
|
|
81
|
-
userAssignments: Record<string, any>;
|
|
82
|
-
roleCategories: any[] | null;
|
|
83
|
-
clientAuthorizations: Record<string, any[] | undefined>;
|
|
84
|
-
userStatsLastFetch: number | null;
|
|
85
|
-
clientsLastFetch: number | null;
|
|
86
|
-
rolesLastFetch: number | null;
|
|
87
|
-
usersLastFetch: number | null;
|
|
88
|
-
roleCategoriesLastFetch: number | null;
|
|
89
|
-
signalrConnection: HubConnection | null;
|
|
90
|
-
signalrConnectionState: HubConnectionState;
|
|
91
|
-
isConnectedToSignalR: boolean;
|
|
92
|
-
}
|
|
93
|
-
export interface AuthActions {
|
|
94
|
-
setSession: (session: AppSession | null) => void;
|
|
95
|
-
clearSession: () => void;
|
|
96
|
-
refreshSession: () => Promise<void>;
|
|
97
|
-
refreshTokens: () => Promise<void>;
|
|
98
|
-
rehydrateSessionAfterRefresh: () => Promise<void>;
|
|
99
|
-
signIn: (credentials: {
|
|
100
|
-
email: string;
|
|
101
|
-
password: string;
|
|
102
|
-
}) => Promise<boolean>;
|
|
103
|
-
signOut: () => Promise<void>;
|
|
104
|
-
forceLogoutAndRedirect: (reason: string) => Promise<void>;
|
|
105
|
-
apiCall: <T = any>(url: string, options?: RequestInit, maxRetries?: number) => Promise<T>;
|
|
106
|
-
makeApiCall: <T = any>(url: string, options?: RequestInit, attempt?: number) => Promise<T>;
|
|
107
|
-
fetchUserStats: (force?: boolean) => Promise<void>;
|
|
108
|
-
fetchClients: (force?: boolean) => Promise<void>;
|
|
109
|
-
fetchRoles: (force?: boolean) => Promise<void>;
|
|
110
|
-
fetchUsers: (params?: any, force?: boolean) => Promise<void>;
|
|
111
|
-
fetchUserDetails: (userId: string, force?: boolean) => Promise<void>;
|
|
112
|
-
fetchUserClientAuthorizations: (userId: string, force?: boolean) => Promise<void>;
|
|
113
|
-
fetchUserRoleAssignments: (userId: string, force?: boolean) => Promise<void>;
|
|
114
|
-
fetchRoleCategories: (force?: boolean) => Promise<void>;
|
|
115
|
-
createUser: (userData: any) => Promise<any>;
|
|
116
|
-
updateUser: (userId: string, updates: any) => Promise<any>;
|
|
117
|
-
deleteUser: (userId: string) => Promise<void>;
|
|
118
|
-
createRole: (roleData: any) => Promise<any>;
|
|
119
|
-
updateRole: (roleId: string, updates: any) => Promise<any>;
|
|
120
|
-
deleteRole: (roleId: string) => Promise<void>;
|
|
121
|
-
assignUserToRole: (userId: string, roleId: string) => Promise<void>;
|
|
122
|
-
removeUserFromRole: (userId: string, roleId: string) => Promise<void>;
|
|
123
|
-
assignUserToClient: (userId: string, clientId: string) => Promise<void>;
|
|
124
|
-
removeUserFromClient: (userId: string, clientId: string) => Promise<void>;
|
|
125
|
-
hasRole: (role: string) => boolean;
|
|
126
|
-
hasAnyRole: (roles: string[]) => boolean;
|
|
127
|
-
hasAllRoles: (roles: string[]) => boolean;
|
|
128
|
-
isFullyAuthenticated: () => boolean;
|
|
129
|
-
setError: (error: string | null) => void;
|
|
130
|
-
clearError: () => void;
|
|
131
|
-
approveUser: (userId: string, reason?: string) => Promise<void>;
|
|
132
|
-
disapproveUser: (userId: string, reason?: string) => Promise<void>;
|
|
133
|
-
pauseUser: (userId: string, reason?: string) => Promise<void>;
|
|
134
|
-
resumeUser: (userId: string) => Promise<void>;
|
|
135
|
-
haltUser: (userId: string, reason?: string) => Promise<void>;
|
|
136
|
-
unlockUser: (userId: string) => Promise<void>;
|
|
137
|
-
canUserAccess: () => boolean;
|
|
138
|
-
getUserStateDisplay: () => string;
|
|
139
|
-
isUserLocked: () => boolean;
|
|
140
|
-
initializeSignalR: () => Promise<void>;
|
|
141
|
-
disconnectSignalR: () => Promise<void>;
|
|
142
|
-
handleUserStateChanged: (data: UserStateChangeEvent) => void;
|
|
143
|
-
}
|
|
144
|
-
export type AuthStore = AuthState & AuthActions;
|
|
145
|
-
export declare const useAuthStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<AuthStore>, "setState"> & {
|
|
146
|
-
setState<A extends string | {
|
|
147
|
-
type: string;
|
|
148
|
-
}>(partial: AuthStore | Partial<AuthStore> | ((state: AuthStore) => AuthStore | Partial<AuthStore>), replace?: boolean | undefined, action?: A | undefined): void;
|
|
149
|
-
}>;
|
|
150
|
-
/**
|
|
151
|
-
* Initialize the auth store with a session (typically called in layout)
|
|
152
|
-
*/
|
|
153
|
-
export declare const initializeAuthStore: (session: AppSession | null) => void;
|
|
154
|
-
export default useAuthStore;
|