@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,469 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* MVP Middleware - Authentication & Route Protection
|
|
4
|
-
*
|
|
5
|
-
* Creates a Next.js middleware handler that protects routes based on:
|
|
6
|
-
* - Authentication status (session cookie → Redis viability check)
|
|
7
|
-
* - 2FA completion status
|
|
8
|
-
* - RBAC permissions (if enabled)
|
|
9
|
-
*
|
|
10
|
-
* Usage: Export the result from your app's middleware.ts:
|
|
11
|
-
* export default createMvpMiddleware();
|
|
12
|
-
*
|
|
13
|
-
* With custom options:
|
|
14
|
-
* export default createMvpMiddleware({
|
|
15
|
-
* circuitBreaker: myCircuitBreaker,
|
|
16
|
-
* logger: myLogger,
|
|
17
|
-
* viabilityEndpoint: '/api/session/refresh-viability',
|
|
18
|
-
* });
|
|
19
|
-
*/
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.createMvpMiddleware = createMvpMiddleware;
|
|
22
|
-
const server_1 = require("next/server");
|
|
23
|
-
const route_config_1 = require("../auth/route-config");
|
|
24
|
-
const internal_api_url_1 = require("../edge/internal-api-url");
|
|
25
|
-
const app_slug_1 = require("../lib/app-slug");
|
|
26
|
-
const rbac_check_1 = require("./rbac-check");
|
|
27
|
-
// =============================================================================
|
|
28
|
-
// DEFAULT IMPLEMENTATIONS
|
|
29
|
-
// =============================================================================
|
|
30
|
-
/** Default no-op circuit breaker (always closed) */
|
|
31
|
-
const defaultCircuitBreaker = {
|
|
32
|
-
isOpen: () => false,
|
|
33
|
-
canAttemptRefresh: () => true,
|
|
34
|
-
recordSuccess: () => { },
|
|
35
|
-
recordFailure: () => { },
|
|
36
|
-
isNetworkError: (error) => {
|
|
37
|
-
return error?.cause?.code === 'ECONNREFUSED' ||
|
|
38
|
-
error?.code === 'ECONNREFUSED' ||
|
|
39
|
-
error?.message?.includes('ECONNREFUSED') ||
|
|
40
|
-
error?.message?.includes('fetch failed') ||
|
|
41
|
-
error?.message?.includes('ENOTFOUND') ||
|
|
42
|
-
error?.message?.includes('ETIMEDOUT') ||
|
|
43
|
-
error?.message?.includes('ECONNRESET');
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
/** Default console logger */
|
|
47
|
-
const defaultLogger = {
|
|
48
|
-
info: (msg, data) => console.log(`[MIDDLEWARE] ${msg}`, data || ''),
|
|
49
|
-
warn: (msg, data) => console.warn(`[MIDDLEWARE] ${msg}`, data || ''),
|
|
50
|
-
error: (msg, data) => console.error(`[MIDDLEWARE] ${msg}`, data || ''),
|
|
51
|
-
};
|
|
52
|
-
// =============================================================================
|
|
53
|
-
// HELPERS
|
|
54
|
-
// =============================================================================
|
|
55
|
-
const LOGIN_PAGE = '/account-auth/login';
|
|
56
|
-
const VERIFY_CODE_PAGE = '/account-auth/verify-code';
|
|
57
|
-
function isLoginPage(pathname) {
|
|
58
|
-
return pathname === LOGIN_PAGE;
|
|
59
|
-
}
|
|
60
|
-
/** Ensures callback URLs never point to auth pages (prevents redirect loops) */
|
|
61
|
-
function getSafeCallbackUrl(pathname, searchParams) {
|
|
62
|
-
if (pathname.startsWith('/account-auth/')) {
|
|
63
|
-
return '/';
|
|
64
|
-
}
|
|
65
|
-
const existing = searchParams?.get('callbackUrl');
|
|
66
|
-
if (existing && !existing.startsWith('/account-auth/')) {
|
|
67
|
-
return existing;
|
|
68
|
-
}
|
|
69
|
-
return pathname;
|
|
70
|
-
}
|
|
71
|
-
/** Clear all session cookies on a response */
|
|
72
|
-
function clearSessionCookies(response, request) {
|
|
73
|
-
const sessionCookie = (0, app_slug_1.getSessionCookieName)();
|
|
74
|
-
const secureCookie = (0, app_slug_1.getSecureSessionCookieName)();
|
|
75
|
-
// Clear main cookies
|
|
76
|
-
response.cookies.set(sessionCookie, '', { path: '/', expires: new Date(0), httpOnly: true, sameSite: 'lax' });
|
|
77
|
-
response.cookies.set(secureCookie, '', { path: '/', expires: new Date(0), httpOnly: true, sameSite: 'lax', secure: true });
|
|
78
|
-
// Clear any chunked cookies (NextAuth chunks large cookies)
|
|
79
|
-
for (const [name] of request.cookies) {
|
|
80
|
-
if (name.startsWith(`${sessionCookie}.`) || name.startsWith(`${secureCookie}.`)) {
|
|
81
|
-
const isSecure = name.startsWith('__Secure-');
|
|
82
|
-
response.cookies.set(name, '', {
|
|
83
|
-
path: '/',
|
|
84
|
-
expires: new Date(0),
|
|
85
|
-
httpOnly: true,
|
|
86
|
-
sameSite: 'lax',
|
|
87
|
-
...(isSecure && { secure: true })
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
/** Create redirect response, optionally clearing cookies */
|
|
93
|
-
function redirectTo(request, location, clearCookies = false) {
|
|
94
|
-
const response = server_1.NextResponse.redirect(new URL(location, request.url));
|
|
95
|
-
if (clearCookies) {
|
|
96
|
-
clearSessionCookies(response, request);
|
|
97
|
-
}
|
|
98
|
-
return response;
|
|
99
|
-
}
|
|
100
|
-
// =============================================================================
|
|
101
|
-
// AUTH DECISION ENGINE
|
|
102
|
-
// =============================================================================
|
|
103
|
-
/**
|
|
104
|
-
* Pure function that determines what action to take based on auth state.
|
|
105
|
-
* No side effects - just examines context and returns a decision.
|
|
106
|
-
*/
|
|
107
|
-
function makeAuthDecision(ctx) {
|
|
108
|
-
const { pathname, isPublicRoute, isLoginPage: onLoginPage, searchParams, sessionPointer, sessionStatus, circuitBreakerOpen } = ctx;
|
|
109
|
-
const safeCallback = getSafeCallbackUrl(pathname);
|
|
110
|
-
// --- Public routes: Allow, but enforce 2FA for authenticated users ---
|
|
111
|
-
if (isPublicRoute && !onLoginPage) {
|
|
112
|
-
if (needsTwoFactorRedirect(pathname, sessionPointer, sessionStatus)) {
|
|
113
|
-
return redirect2FA(safeCallback);
|
|
114
|
-
}
|
|
115
|
-
return { type: 'allow' };
|
|
116
|
-
}
|
|
117
|
-
// --- Circuit breaker open: Service degraded ---
|
|
118
|
-
if (circuitBreakerOpen) {
|
|
119
|
-
if (onLoginPage)
|
|
120
|
-
return { type: 'allow' };
|
|
121
|
-
return {
|
|
122
|
-
type: 'redirect',
|
|
123
|
-
location: `${LOGIN_PAGE}?error=ServiceUnavailable`,
|
|
124
|
-
reason: 'circuit_breaker_open',
|
|
125
|
-
clearCookies: true
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
// --- No session cookie: Need to login ---
|
|
129
|
-
if (!sessionPointer.exists) {
|
|
130
|
-
if (onLoginPage)
|
|
131
|
-
return { type: 'allow' };
|
|
132
|
-
if (pathname === '/') {
|
|
133
|
-
const unauthUrl = process.env.UNAUTHENTICATED_REDIRECT_URL || '/account-auth/login';
|
|
134
|
-
return { type: 'redirect', location: unauthUrl, reason: 'unauthenticated_root' };
|
|
135
|
-
}
|
|
136
|
-
if (pathname.startsWith('/api/')) {
|
|
137
|
-
return { type: 'allow' }; // Let API return proper 401 JSON
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
type: 'redirect',
|
|
141
|
-
location: `${LOGIN_PAGE}?callbackUrl=${encodeURIComponent(safeCallback)}`,
|
|
142
|
-
reason: 'no_session'
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
// --- Service error: Can't verify session ---
|
|
146
|
-
if (sessionStatus.exists === null || sessionStatus.forceInvalid === null) {
|
|
147
|
-
return { type: 'service_error', reason: 'viability_check_failed' };
|
|
148
|
-
}
|
|
149
|
-
// --- Session force-invalidated (admin action, password change, etc.) ---
|
|
150
|
-
if (sessionStatus.forceInvalid) {
|
|
151
|
-
if (onLoginPage)
|
|
152
|
-
return { type: 'allow' };
|
|
153
|
-
if (pathname.startsWith('/api/'))
|
|
154
|
-
return { type: 'allow' };
|
|
155
|
-
return {
|
|
156
|
-
type: 'redirect',
|
|
157
|
-
location: `${LOGIN_PAGE}?callbackUrl=${encodeURIComponent(safeCallback)}&reason=invalidated`,
|
|
158
|
-
reason: 'force_invalidated',
|
|
159
|
-
clearCookies: true
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
// --- Stale session (cookie exists but Redis entry gone) ---
|
|
163
|
-
if (!sessionStatus.exists) {
|
|
164
|
-
if (onLoginPage)
|
|
165
|
-
return { type: 'allow' };
|
|
166
|
-
if (pathname.startsWith('/api/'))
|
|
167
|
-
return { type: 'allow' };
|
|
168
|
-
return {
|
|
169
|
-
type: 'redirect',
|
|
170
|
-
location: `${LOGIN_PAGE}?callbackUrl=${encodeURIComponent(safeCallback)}&reason=stale`,
|
|
171
|
-
reason: 'stale_session',
|
|
172
|
-
clearCookies: true
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
// --- 2FA required but not completed ---
|
|
176
|
-
if (needsTwoFactorRedirect(pathname, sessionPointer, sessionStatus)) {
|
|
177
|
-
if (onLoginPage) {
|
|
178
|
-
const cb = getSafeCallbackUrl(pathname, searchParams);
|
|
179
|
-
return { type: 'redirect', location: `${VERIFY_CODE_PAGE}?callbackUrl=${encodeURIComponent(cb)}`, reason: '2fa_from_login' };
|
|
180
|
-
}
|
|
181
|
-
return redirect2FA(safeCallback);
|
|
182
|
-
}
|
|
183
|
-
// --- Token expired: Try refresh ---
|
|
184
|
-
if (sessionPointer.expired) {
|
|
185
|
-
if (onLoginPage)
|
|
186
|
-
return { type: 'allow' };
|
|
187
|
-
if (sessionPointer.hasRefreshToken) {
|
|
188
|
-
return { type: 'refresh_needed' };
|
|
189
|
-
}
|
|
190
|
-
return {
|
|
191
|
-
type: 'redirect',
|
|
192
|
-
location: `${LOGIN_PAGE}?callbackUrl=${encodeURIComponent(safeCallback)}&error=SessionExpired`,
|
|
193
|
-
reason: 'token_expired_no_refresh'
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
// --- Authenticated user on login page: Send to their destination ---
|
|
197
|
-
if (onLoginPage) {
|
|
198
|
-
const dest = getSafeCallbackUrl(pathname, searchParams);
|
|
199
|
-
return { type: 'redirect', location: dest, reason: 'already_authenticated' };
|
|
200
|
-
}
|
|
201
|
-
// --- All checks passed ---
|
|
202
|
-
return { type: 'allow' };
|
|
203
|
-
}
|
|
204
|
-
/** Check if user needs 2FA redirect */
|
|
205
|
-
function needsTwoFactorRedirect(pathname, session, status) {
|
|
206
|
-
if (!session.exists || !status.exists)
|
|
207
|
-
return false;
|
|
208
|
-
if (!status.requires2FA || status.twoFactorComplete)
|
|
209
|
-
return false;
|
|
210
|
-
if (pathname === VERIFY_CODE_PAGE)
|
|
211
|
-
return false;
|
|
212
|
-
if ((0, route_config_1.should2FABypass)(pathname))
|
|
213
|
-
return false;
|
|
214
|
-
if (pathname.startsWith('/api/'))
|
|
215
|
-
return false; // APIs return JSON errors
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
function redirect2FA(callbackUrl) {
|
|
219
|
-
return {
|
|
220
|
-
type: 'redirect',
|
|
221
|
-
location: `${VERIFY_CODE_PAGE}?callbackUrl=${encodeURIComponent(callbackUrl)}`,
|
|
222
|
-
reason: '2fa_required'
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
// =============================================================================
|
|
226
|
-
// MIDDLEWARE FACTORY
|
|
227
|
-
// =============================================================================
|
|
228
|
-
function createMvpMiddleware(options = {}) {
|
|
229
|
-
// Resolve options with defaults
|
|
230
|
-
const cb = options.circuitBreaker || defaultCircuitBreaker;
|
|
231
|
-
const log = options.logger || defaultLogger;
|
|
232
|
-
const viabilityEndpoint = options.viabilityEndpoint || '/api/session/viability';
|
|
233
|
-
const refreshEndpoint = options.refreshEndpoint || '/api/auth/refresh';
|
|
234
|
-
const bypassPaths = options.bypassPaths || [];
|
|
235
|
-
const rbacExemptPaths = options.rbacExemptPaths || [];
|
|
236
|
-
return async function middleware(request) {
|
|
237
|
-
const { pathname, searchParams } = request.nextUrl;
|
|
238
|
-
// =========================================================================
|
|
239
|
-
// CRITICAL: Auth routes MUST bypass middleware
|
|
240
|
-
// =========================================================================
|
|
241
|
-
// These routes are called internally by middleware itself (viability check,
|
|
242
|
-
// token refresh). Without this bypass, we get infinite loops or 403s.
|
|
243
|
-
// This has caused production outages. DO NOT REMOVE.
|
|
244
|
-
// =========================================================================
|
|
245
|
-
if (pathname.startsWith('/api/auth/') || pathname.startsWith('/api/session/')) {
|
|
246
|
-
return server_1.NextResponse.next();
|
|
247
|
-
}
|
|
248
|
-
// Check custom bypass paths
|
|
249
|
-
for (const bypassPath of bypassPaths) {
|
|
250
|
-
if (pathname.startsWith(bypassPath)) {
|
|
251
|
-
return server_1.NextResponse.next();
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
const isPublic = (0, route_config_1.isUnauthenticatedRoute)(pathname);
|
|
255
|
-
const isLogin = isLoginPage(pathname);
|
|
256
|
-
// --- Optimization: Skip viability check for unauthenticated public browsing ---
|
|
257
|
-
if (isPublic && !isLogin) {
|
|
258
|
-
const hasCookie = request.cookies.get((0, app_slug_1.getSessionCookieName)())?.value ||
|
|
259
|
-
request.cookies.get((0, app_slug_1.getSecureSessionCookieName)())?.value;
|
|
260
|
-
if (!hasCookie) {
|
|
261
|
-
return server_1.NextResponse.next();
|
|
262
|
-
}
|
|
263
|
-
// Has cookie - continue to viability check for 2FA enforcement
|
|
264
|
-
}
|
|
265
|
-
// --- Fetch session viability from internal API ---
|
|
266
|
-
const { sessionStatus, sessionPointer } = await checkViability(request, viabilityEndpoint, log);
|
|
267
|
-
// --- Handle stale session early (cookie exists but session doesn't) ---
|
|
268
|
-
if (!isPublic && sessionStatus.exists === false && sessionPointer.sessionToken) {
|
|
269
|
-
const safeCallback = getSafeCallbackUrl(pathname);
|
|
270
|
-
log.warn('Stale session detected', {
|
|
271
|
-
sessionToken: sessionPointer.sessionToken?.substring(0, 8) + '...',
|
|
272
|
-
pathname
|
|
273
|
-
});
|
|
274
|
-
return redirectTo(request, `${LOGIN_PAGE}?callbackUrl=${encodeURIComponent(safeCallback)}`, true);
|
|
275
|
-
}
|
|
276
|
-
// --- Run decision engine ---
|
|
277
|
-
const decision = makeAuthDecision({
|
|
278
|
-
pathname,
|
|
279
|
-
isPublicRoute: isPublic,
|
|
280
|
-
isLoginPage: isLogin,
|
|
281
|
-
searchParams,
|
|
282
|
-
sessionPointer,
|
|
283
|
-
sessionStatus,
|
|
284
|
-
circuitBreakerOpen: cb.isOpen(),
|
|
285
|
-
});
|
|
286
|
-
// --- Execute decision ---
|
|
287
|
-
return executeDecision(request, decision, pathname, sessionPointer, sessionStatus, {
|
|
288
|
-
circuitBreaker: cb,
|
|
289
|
-
logger: log,
|
|
290
|
-
refreshEndpoint,
|
|
291
|
-
rbacExemptPaths,
|
|
292
|
-
onRefreshSuccess: options.onRefreshSuccess,
|
|
293
|
-
onRefreshFailure: options.onRefreshFailure,
|
|
294
|
-
});
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
/** Check session viability via internal API */
|
|
298
|
-
async function checkViability(request, endpoint, log) {
|
|
299
|
-
const sessionStatus = {
|
|
300
|
-
exists: false,
|
|
301
|
-
forceInvalid: false,
|
|
302
|
-
requires2FA: false,
|
|
303
|
-
twoFactorComplete: false,
|
|
304
|
-
};
|
|
305
|
-
const sessionPointer = {
|
|
306
|
-
exists: false,
|
|
307
|
-
sessionToken: undefined,
|
|
308
|
-
expired: false,
|
|
309
|
-
hasRefreshToken: false,
|
|
310
|
-
roles: [],
|
|
311
|
-
clientId: '',
|
|
312
|
-
};
|
|
313
|
-
try {
|
|
314
|
-
const baseUrl = (0, internal_api_url_1.getInternalApiUrl)(request);
|
|
315
|
-
const response = await fetch(new URL(endpoint, baseUrl), {
|
|
316
|
-
method: 'GET',
|
|
317
|
-
headers: {
|
|
318
|
-
'Accept': 'application/json',
|
|
319
|
-
'Cache-Control': 'no-store',
|
|
320
|
-
'Cookie': request.headers.get('cookie') || ''
|
|
321
|
-
},
|
|
322
|
-
credentials: 'include',
|
|
323
|
-
signal: AbortSignal.timeout(5000),
|
|
324
|
-
});
|
|
325
|
-
if (response.ok) {
|
|
326
|
-
const data = await response.json();
|
|
327
|
-
// Support both response formats (viability and refresh-viability)
|
|
328
|
-
sessionStatus.exists = data.authenticated ?? (data.sessionToken && data.reason !== 'session_not_found');
|
|
329
|
-
sessionStatus.requires2FA = data.requires2FA || false;
|
|
330
|
-
sessionStatus.twoFactorComplete = data.twoFactorComplete || false;
|
|
331
|
-
sessionPointer.exists = sessionStatus.exists ?? false;
|
|
332
|
-
sessionPointer.sessionToken = data.sessionToken;
|
|
333
|
-
sessionPointer.expired = data.accessTokenExpired || false;
|
|
334
|
-
sessionPointer.hasRefreshToken = data.hasRefreshToken ?? data.canRefresh ?? false;
|
|
335
|
-
sessionPointer.roles = data.roles || [];
|
|
336
|
-
sessionPointer.clientId = data.clientId || '';
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
log.error('Viability check failed', { status: response.status });
|
|
340
|
-
sessionStatus.exists = null;
|
|
341
|
-
sessionStatus.forceInvalid = null;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
catch (error) {
|
|
345
|
-
log.error('Viability check error', { error: error instanceof Error ? error.message : String(error) });
|
|
346
|
-
sessionStatus.exists = null;
|
|
347
|
-
sessionStatus.forceInvalid = null;
|
|
348
|
-
}
|
|
349
|
-
return { sessionStatus, sessionPointer };
|
|
350
|
-
}
|
|
351
|
-
/** Execute the auth decision */
|
|
352
|
-
async function executeDecision(request, decision, pathname, sessionPointer, sessionStatus, opts) {
|
|
353
|
-
const safeCallback = getSafeCallbackUrl(pathname);
|
|
354
|
-
switch (decision.type) {
|
|
355
|
-
case 'allow':
|
|
356
|
-
return handleAllow(request, pathname, sessionPointer, sessionStatus, opts.rbacExemptPaths);
|
|
357
|
-
case 'redirect':
|
|
358
|
-
return redirectTo(request, decision.location, decision.clearCookies);
|
|
359
|
-
case 'service_error':
|
|
360
|
-
return server_1.NextResponse.redirect(new URL('/service-unavailable', request.url));
|
|
361
|
-
case 'refresh_needed':
|
|
362
|
-
return handleRefresh(request, safeCallback, opts);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
/** Paths that must never be RBAC-checked (they are RBAC redirect targets) */
|
|
366
|
-
const RBAC_EXEMPT_PATHS = ['/error', '/unauthorized', '/service-unavailable'];
|
|
367
|
-
/** Handle 'allow' decision - run RBAC if enabled */
|
|
368
|
-
async function handleAllow(request, pathname, sessionPointer, sessionStatus, rbacExemptPaths = []) {
|
|
369
|
-
const isPublic = (0, route_config_1.isUnauthenticatedRoute)(pathname);
|
|
370
|
-
if ((0, rbac_check_1.isRBACEnabled)() && !isPublic && sessionPointer.exists) {
|
|
371
|
-
// Skip RBAC for error/fallback pages (prevent redirect loops) and app-configured exempt paths
|
|
372
|
-
if (RBAC_EXEMPT_PATHS.some(p => pathname.startsWith(p)) ||
|
|
373
|
-
rbacExemptPaths.some(p => pathname.startsWith(p))) {
|
|
374
|
-
return server_1.NextResponse.next();
|
|
375
|
-
}
|
|
376
|
-
if (!sessionPointer.clientId) {
|
|
377
|
-
console.error('[MIDDLEWARE] RBAC: No clientId — returning 401');
|
|
378
|
-
if (pathname.startsWith('/api/')) {
|
|
379
|
-
return server_1.NextResponse.json({ error: 'Unauthorized — missing clientId for RBAC' }, { status: 401 });
|
|
380
|
-
}
|
|
381
|
-
return server_1.NextResponse.redirect(new URL('/unauthorized', request.url));
|
|
382
|
-
}
|
|
383
|
-
try {
|
|
384
|
-
const result = await (0, rbac_check_1.checkPagePermission)(pathname, sessionPointer.roles, sessionPointer.clientId);
|
|
385
|
-
if (!result.allowed) {
|
|
386
|
-
console.log('[MIDDLEWARE] RBAC denied:', { pathname, reason: result.reason });
|
|
387
|
-
// In development, fail open - RBAC API may not be fully configured
|
|
388
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
389
|
-
console.warn('[MIDDLEWARE] RBAC: Allowing in development despite denial:', result.reason);
|
|
390
|
-
return server_1.NextResponse.next();
|
|
391
|
-
}
|
|
392
|
-
return server_1.NextResponse.redirect(new URL(result.redirect || '/unauthorized', request.url));
|
|
393
|
-
}
|
|
394
|
-
if (result.requires_2fa && !sessionStatus.twoFactorComplete) {
|
|
395
|
-
return server_1.NextResponse.redirect(new URL(`${VERIFY_CODE_PAGE}?callbackUrl=${encodeURIComponent(pathname)}`, request.url));
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
catch (error) {
|
|
399
|
-
console.error('[MIDDLEWARE] RBAC error:', error);
|
|
400
|
-
// In development, fail open
|
|
401
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
402
|
-
console.warn('[MIDDLEWARE] RBAC: Allowing in development despite error');
|
|
403
|
-
return server_1.NextResponse.next();
|
|
404
|
-
}
|
|
405
|
-
return server_1.NextResponse.redirect(new URL('/error?code=rbac_error', request.url));
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
return server_1.NextResponse.next();
|
|
409
|
-
}
|
|
410
|
-
/** Handle token refresh */
|
|
411
|
-
async function handleRefresh(request, safeCallback, opts) {
|
|
412
|
-
const { circuitBreaker: cb, logger: log, refreshEndpoint, onRefreshSuccess, onRefreshFailure } = opts;
|
|
413
|
-
// Check if circuit breaker allows refresh attempt
|
|
414
|
-
if (!cb.canAttemptRefresh()) {
|
|
415
|
-
log.warn('Circuit breaker preventing refresh attempt');
|
|
416
|
-
return redirectTo(request, `${LOGIN_PAGE}?callbackUrl=${encodeURIComponent(safeCallback)}&error=ServiceUnavailable`, true);
|
|
417
|
-
}
|
|
418
|
-
try {
|
|
419
|
-
const baseUrl = (0, internal_api_url_1.getInternalApiUrl)(request);
|
|
420
|
-
const response = await fetch(new URL(refreshEndpoint, baseUrl), {
|
|
421
|
-
method: 'POST',
|
|
422
|
-
headers: {
|
|
423
|
-
'Accept': 'application/json',
|
|
424
|
-
'Content-Type': 'application/json',
|
|
425
|
-
'Cookie': request.headers.get('cookie') || '',
|
|
426
|
-
'x-session-token': request.cookies.get((0, app_slug_1.getSessionCookieName)())?.value ||
|
|
427
|
-
request.cookies.get((0, app_slug_1.getSecureSessionCookieName)())?.value || ''
|
|
428
|
-
},
|
|
429
|
-
credentials: 'include',
|
|
430
|
-
signal: AbortSignal.timeout(5000),
|
|
431
|
-
});
|
|
432
|
-
if (response.ok) {
|
|
433
|
-
const data = await response.json();
|
|
434
|
-
if (data.refreshed || data.reason === 'already_fresh') {
|
|
435
|
-
cb.recordSuccess();
|
|
436
|
-
onRefreshSuccess?.();
|
|
437
|
-
log.info('Token refresh successful');
|
|
438
|
-
return server_1.NextResponse.next();
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
// Refresh failed - check for permanent failures (401/403) vs transient (5xx)
|
|
442
|
-
// CRITICAL: Always clear cookies on 401/403 to prevent redirect loops
|
|
443
|
-
// CRITICAL: Only record circuit breaker failures for network errors, not HTTP errors
|
|
444
|
-
// HTTP 500 means the server responded - it's reachable. Only network failures should trip the breaker.
|
|
445
|
-
const isPermanentFailure = response.status === 401 || response.status === 403;
|
|
446
|
-
const errorParam = isPermanentFailure ? 'SessionExpired' : 'RefreshError';
|
|
447
|
-
log.warn('Refresh failed', {
|
|
448
|
-
status: response.status,
|
|
449
|
-
isPermanentFailure,
|
|
450
|
-
clearingCookies: isPermanentFailure
|
|
451
|
-
});
|
|
452
|
-
onRefreshFailure?.(response.status, false);
|
|
453
|
-
return redirectTo(request, `${LOGIN_PAGE}?callbackUrl=${encodeURIComponent(safeCallback)}&error=${errorParam}`, isPermanentFailure);
|
|
454
|
-
}
|
|
455
|
-
catch (error) {
|
|
456
|
-
const isNetwork = cb.isNetworkError(error);
|
|
457
|
-
log.error('Refresh error', {
|
|
458
|
-
error: error instanceof Error ? error.message : String(error),
|
|
459
|
-
isNetworkError: isNetwork
|
|
460
|
-
});
|
|
461
|
-
// Only record circuit breaker failure for actual network errors
|
|
462
|
-
if (isNetwork) {
|
|
463
|
-
cb.recordFailure(error);
|
|
464
|
-
}
|
|
465
|
-
onRefreshFailure?.(0, isNetwork);
|
|
466
|
-
// Network error - don't clear cookies, might be transient
|
|
467
|
-
return redirectTo(request, `${LOGIN_PAGE}?callbackUrl=${encodeURIComponent(safeCallback)}&error=RefreshError`, false);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Page RBAC Check Module
|
|
3
|
-
*
|
|
4
|
-
* Checks page-level permissions via Vibe API through the IDP Proxy.
|
|
5
|
-
* Uses in-memory cache to reduce API calls.
|
|
6
|
-
* Fails closed (DENY) on errors or timeout.
|
|
7
|
-
*
|
|
8
|
-
* All requests route through the IDP Vibe Proxy ({IDP_URL}/api/vibe/proxy)
|
|
9
|
-
* which injects proper HMAC credentials for the Vibe API.
|
|
10
|
-
*
|
|
11
|
-
* @version 2.0.0
|
|
12
|
-
* @since page-rbac-2026-01
|
|
13
|
-
*/
|
|
14
|
-
export interface RBACResult {
|
|
15
|
-
allowed: boolean;
|
|
16
|
-
requires_2fa?: boolean;
|
|
17
|
-
requires_elevated_auth?: boolean;
|
|
18
|
-
reason?: string;
|
|
19
|
-
required_roles?: string[];
|
|
20
|
-
required_claims?: Array<{
|
|
21
|
-
type: string;
|
|
22
|
-
value: string;
|
|
23
|
-
}>;
|
|
24
|
-
matched_rule?: string;
|
|
25
|
-
redirect?: string;
|
|
26
|
-
cache_ttl?: number;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Clear cache (for testing or config changes).
|
|
30
|
-
*/
|
|
31
|
-
export declare function clearRBACCache(): void;
|
|
32
|
-
/**
|
|
33
|
-
* Check if user has permission to access a page.
|
|
34
|
-
*
|
|
35
|
-
* Routes through IDP Vibe Proxy ({IDP_URL}/api/vibe/proxy) which injects
|
|
36
|
-
* proper HMAC credentials. The Vibe RBAC endpoint requires client context
|
|
37
|
-
* that only the proxy can provide.
|
|
38
|
-
*
|
|
39
|
-
* FAIL CLOSED: If proxy is unreachable or times out, access is DENIED.
|
|
40
|
-
*
|
|
41
|
-
* @param path - The route path to check
|
|
42
|
-
* @param userRoles - User's roles from session
|
|
43
|
-
* @param clientId - Client slug for multi-tenancy
|
|
44
|
-
* @param userClaims - Optional claims for claim-based authorization
|
|
45
|
-
* @returns RBAC result with allowed/denied status
|
|
46
|
-
*/
|
|
47
|
-
export declare function checkPagePermission(path: string, userRoles: string[], clientId: string, userClaims?: Record<string, string>): Promise<RBACResult>;
|
|
48
|
-
/**
|
|
49
|
-
* Check if RBAC is enabled for this deployment.
|
|
50
|
-
*/
|
|
51
|
-
export declare function isRBACEnabled(): boolean;
|