@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,213 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* NextAuth Configuration (Refactored)
|
|
4
|
-
*
|
|
5
|
-
* This is the composition layer that wires together all auth modules.
|
|
6
|
-
* Individual logic lives in dedicated modules:
|
|
7
|
-
* - providers/ - Credentials and OAuth provider builders
|
|
8
|
-
* - callbacks/ - JWT, session, signIn callbacks
|
|
9
|
-
* - events/ - SignOut event handler
|
|
10
|
-
* - utils/ - Token utilities, IDP client
|
|
11
|
-
* - types/ - Type definitions
|
|
12
|
-
*
|
|
13
|
-
* CARGO CULT PATTERNS REMOVED:
|
|
14
|
-
* ============================
|
|
15
|
-
* The original auth-options.ts (1186 lines) had several anti-patterns that
|
|
16
|
-
* added complexity without benefit:
|
|
17
|
-
*
|
|
18
|
-
* 1. CALLBACK CONCURRENCY PROTECTION (removed)
|
|
19
|
-
* - shouldExecuteCallback() / markCallbackComplete()
|
|
20
|
-
* - A debouncing mechanism that tried to prevent callbacks from running
|
|
21
|
-
* too frequently. NextAuth already handles this properly.
|
|
22
|
-
* - Added complexity, caused race condition bugs, and leaked memory
|
|
23
|
-
* (Map entries never cleaned up).
|
|
24
|
-
*
|
|
25
|
-
* 2. SESSION RESTORATION (removed)
|
|
26
|
-
* - attemptSessionRestoration()
|
|
27
|
-
* - Tried to restore sessions by calling refresh endpoint from JWT callback.
|
|
28
|
-
* - Created circular dependencies and made debugging impossible.
|
|
29
|
-
* - Clean approach: Session missing = user re-authenticates. Simple.
|
|
30
|
-
*
|
|
31
|
-
* 3. VARIABLE NAME SOUP (normalized in Phase 3)
|
|
32
|
-
* - accessToken vs idpAccessToken vs oauthAccessToken
|
|
33
|
-
* - twoFactorComplete vs mfaVerified vs requiresTwoFactor
|
|
34
|
-
* - sessionToken vs redisSessionId
|
|
35
|
-
* - Now: Clear prefixes (idp*, oauth*, mfa*) with documented meanings.
|
|
36
|
-
*
|
|
37
|
-
* 4. INLINE EVERYTHING (modularized in Phase 2)
|
|
38
|
-
* - All logic was in one giant file with no separation of concerns.
|
|
39
|
-
* - Now: Each module has one job and can be tested independently.
|
|
40
|
-
*
|
|
41
|
-
* @version 2.0.0
|
|
42
|
-
* @since auth-refactor-2026-01
|
|
43
|
-
*/
|
|
44
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.authOptions = void 0;
|
|
46
|
-
exports.getAuthOptions = getAuthOptions;
|
|
47
|
-
exports.clearAuthOptionsCache = clearAuthOptionsCache;
|
|
48
|
-
const jwt_1 = require("next-auth/jwt");
|
|
49
|
-
const idp_client_config_1 = require("../lib/idp-client-config");
|
|
50
|
-
const app_slug_1 = require("../lib/app-slug");
|
|
51
|
-
// Module imports
|
|
52
|
-
const providers_1 = require("./providers");
|
|
53
|
-
const callbacks_1 = require("./callbacks");
|
|
54
|
-
const events_1 = require("./events");
|
|
55
|
-
// ============================================================================
|
|
56
|
-
// ENVIRONMENT HELPERS
|
|
57
|
-
// ============================================================================
|
|
58
|
-
/**
|
|
59
|
-
* Get AUTH_ISSUER_URL for JWT issuer claim.
|
|
60
|
-
* Required for SSO across apps.
|
|
61
|
-
*/
|
|
62
|
-
function getAuthIssuerUrl() {
|
|
63
|
-
const url = process.env.AUTH_ISSUER_URL;
|
|
64
|
-
if (!url) {
|
|
65
|
-
throw new Error('AUTH_ISSUER_URL environment variable is REQUIRED');
|
|
66
|
-
}
|
|
67
|
-
return url;
|
|
68
|
-
}
|
|
69
|
-
// ============================================================================
|
|
70
|
-
// BASE AUTH OPTIONS
|
|
71
|
-
// ============================================================================
|
|
72
|
-
/**
|
|
73
|
-
* Base NextAuth configuration.
|
|
74
|
-
* Use getAuthOptions() for dynamic provider loading from IDP.
|
|
75
|
-
*/
|
|
76
|
-
exports.authOptions = {
|
|
77
|
-
// Session uses JWT strategy - JWT contains only redisSessionId
|
|
78
|
-
session: {
|
|
79
|
-
strategy: 'jwt',
|
|
80
|
-
maxAge: 30 * 24 * 60 * 60, // 30 days default, overridden by IDP config
|
|
81
|
-
},
|
|
82
|
-
// Custom JWT handling for SSO issuer
|
|
83
|
-
jwt: {
|
|
84
|
-
encode: async (params) => {
|
|
85
|
-
try {
|
|
86
|
-
const issuer = getAuthIssuerUrl();
|
|
87
|
-
console.log('[JWT_ENCODE] Encoding token:', {
|
|
88
|
-
hasToken: !!params.token,
|
|
89
|
-
hasSecret: !!params.secret,
|
|
90
|
-
secretLength: params.secret?.length || 0,
|
|
91
|
-
issuer,
|
|
92
|
-
tokenKeys: params.token ? Object.keys(params.token) : [],
|
|
93
|
-
});
|
|
94
|
-
const encoded = await (0, jwt_1.encode)({
|
|
95
|
-
...params,
|
|
96
|
-
secret: params.secret,
|
|
97
|
-
token: {
|
|
98
|
-
...params.token,
|
|
99
|
-
iss: issuer,
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
console.log('[JWT_ENCODE] Success, encoded length:', encoded?.length || 0);
|
|
103
|
-
return encoded;
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
console.error('[JWT_ENCODE] FAILED:', error);
|
|
107
|
-
throw error;
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
decode: async (params) => {
|
|
111
|
-
const decoded = await (0, jwt_1.decode)(params);
|
|
112
|
-
if (decoded?.iss && decoded.iss !== getAuthIssuerUrl()) {
|
|
113
|
-
console.error('[JWT] Invalid issuer. Expected:', getAuthIssuerUrl(), 'Got:', decoded.iss);
|
|
114
|
-
return null; // Hard enforcement - reject mismatched issuers
|
|
115
|
-
}
|
|
116
|
-
return decoded;
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
// Cookie configuration for multi-app support
|
|
120
|
-
// In production, use __Secure- prefixed cookie names for enhanced security
|
|
121
|
-
cookies: {
|
|
122
|
-
sessionToken: {
|
|
123
|
-
name: process.env.NODE_ENV === 'production' ? (0, app_slug_1.getSecureSessionCookieName)() : (0, app_slug_1.getSessionCookieName)(),
|
|
124
|
-
options: {
|
|
125
|
-
httpOnly: true,
|
|
126
|
-
sameSite: 'lax',
|
|
127
|
-
path: '/',
|
|
128
|
-
secure: process.env.NODE_ENV === 'production',
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
csrfToken: {
|
|
132
|
-
name: process.env.NODE_ENV === 'production' ? (0, app_slug_1.getSecureCsrfCookieName)() : (0, app_slug_1.getCsrfCookieName)(),
|
|
133
|
-
options: {
|
|
134
|
-
httpOnly: true,
|
|
135
|
-
sameSite: 'lax',
|
|
136
|
-
path: '/',
|
|
137
|
-
secure: process.env.NODE_ENV === 'production',
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
callbackUrl: {
|
|
141
|
-
name: (0, app_slug_1.getCallbackUrlCookieName)(),
|
|
142
|
-
options: {
|
|
143
|
-
sameSite: 'lax',
|
|
144
|
-
path: '/',
|
|
145
|
-
secure: process.env.NODE_ENV === 'production',
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
// Providers - credentials only in base, OAuth added dynamically
|
|
150
|
-
providers: [(0, providers_1.createCredentialsProvider)()],
|
|
151
|
-
// Callbacks wired to modular implementations
|
|
152
|
-
callbacks: {
|
|
153
|
-
jwt: callbacks_1.jwtCallback,
|
|
154
|
-
session: callbacks_1.sessionCallback, // Type cast needed for NextAuth compatibility
|
|
155
|
-
signIn: callbacks_1.signInCallback,
|
|
156
|
-
},
|
|
157
|
-
// Events
|
|
158
|
-
events: {
|
|
159
|
-
signOut: events_1.handleSignOut,
|
|
160
|
-
},
|
|
161
|
-
// Custom pages
|
|
162
|
-
pages: {
|
|
163
|
-
signIn: '/account-auth/login',
|
|
164
|
-
error: '/account-auth/login',
|
|
165
|
-
},
|
|
166
|
-
debug: false,
|
|
167
|
-
};
|
|
168
|
-
// ============================================================================
|
|
169
|
-
// DYNAMIC AUTH OPTIONS (WITH IDP OAUTH PROVIDERS)
|
|
170
|
-
// ============================================================================
|
|
171
|
-
let cachedAuthOptions = null;
|
|
172
|
-
let authOptionsPromise = null;
|
|
173
|
-
/**
|
|
174
|
-
* Get auth options with dynamically loaded OAuth providers from IDP.
|
|
175
|
-
* Uses caching to avoid rebuilding on every request.
|
|
176
|
-
*/
|
|
177
|
-
async function getAuthOptions() {
|
|
178
|
-
if (cachedAuthOptions) {
|
|
179
|
-
return cachedAuthOptions;
|
|
180
|
-
}
|
|
181
|
-
if (authOptionsPromise) {
|
|
182
|
-
return authOptionsPromise;
|
|
183
|
-
}
|
|
184
|
-
authOptionsPromise = buildDynamicAuthOptions();
|
|
185
|
-
cachedAuthOptions = await authOptionsPromise;
|
|
186
|
-
authOptionsPromise = null;
|
|
187
|
-
return cachedAuthOptions;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Build auth options with dynamic OAuth providers from IDP.
|
|
191
|
-
*/
|
|
192
|
-
async function buildDynamicAuthOptions() {
|
|
193
|
-
const idpConfig = await (0, idp_client_config_1.getIDPClientConfig)();
|
|
194
|
-
const oauthProviders = (0, providers_1.buildOAuthProviders)(idpConfig);
|
|
195
|
-
return {
|
|
196
|
-
...exports.authOptions,
|
|
197
|
-
secret: idpConfig.nextAuthSecret || process.env.NEXTAUTH_SECRET,
|
|
198
|
-
session: {
|
|
199
|
-
...exports.authOptions.session,
|
|
200
|
-
maxAge: idpConfig.authSettings?.rememberMeDays
|
|
201
|
-
? idpConfig.authSettings.rememberMeDays * 24 * 60 * 60
|
|
202
|
-
: 30 * 24 * 60 * 60,
|
|
203
|
-
},
|
|
204
|
-
providers: [(0, providers_1.createCredentialsProvider)(), ...oauthProviders],
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Clear cached auth options (when IDP config changes).
|
|
209
|
-
*/
|
|
210
|
-
function clearAuthOptionsCache() {
|
|
211
|
-
cachedAuthOptions = null;
|
|
212
|
-
authOptionsPromise = null;
|
|
213
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Better Auth Configuration (Phase 1 — parallel install)
|
|
3
|
-
*
|
|
4
|
-
* NOT wired to routes yet. Exists alongside auth-options.ts for testing.
|
|
5
|
-
* Wired in Phase 2 behind USE_BETTER_AUTH flag.
|
|
6
|
-
*
|
|
7
|
-
* Architecture: No database adapter — Better Auth runs in stateless mode
|
|
8
|
-
* with JWE cookie cache. User management stays on IDP, sessions on Redis.
|
|
9
|
-
*
|
|
10
|
-
* @see BETTER-AUTH-MIGRATION-SPEC.md
|
|
11
|
-
*/
|
|
12
|
-
import 'server-only';
|
|
13
|
-
import type { IDPClientConfig } from '../lib/idp-client-config';
|
|
14
|
-
/**
|
|
15
|
-
* Better Auth social provider config shape.
|
|
16
|
-
*/
|
|
17
|
-
export interface BetterAuthSocialProvider {
|
|
18
|
-
clientId: string;
|
|
19
|
-
clientSecret: string;
|
|
20
|
-
scope?: string[];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Build Better Auth social providers from IDP config.
|
|
24
|
-
* Replaces buildOAuthProviders() from providers/oauth.ts.
|
|
25
|
-
*/
|
|
26
|
-
export declare function buildBetterAuthProviders(config: IDPClientConfig): Record<string, BetterAuthSocialProvider>;
|
|
27
|
-
/**
|
|
28
|
-
* Create Better Auth instance from IDP config.
|
|
29
|
-
*
|
|
30
|
-
* No database — runs in stateless mode with JWE cookie cache.
|
|
31
|
-
* Call after getIDPClientConfig() resolves.
|
|
32
|
-
*/
|
|
33
|
-
export declare function createBetterAuthInstance(idpConfig: IDPClientConfig): import("better-auth").Auth<{
|
|
34
|
-
secret: string;
|
|
35
|
-
socialProviders: Record<string, BetterAuthSocialProvider>;
|
|
36
|
-
trustedOrigins: string[];
|
|
37
|
-
session: {
|
|
38
|
-
cookieCache: {
|
|
39
|
-
enabled: true;
|
|
40
|
-
maxAge: number;
|
|
41
|
-
refreshCache: true;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
plugins: [{
|
|
45
|
-
id: "next-cookies";
|
|
46
|
-
hooks: {
|
|
47
|
-
before: {
|
|
48
|
-
matcher(ctx: import("better-auth").HookEndpointContext): boolean;
|
|
49
|
-
handler: (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>;
|
|
50
|
-
}[];
|
|
51
|
-
after: {
|
|
52
|
-
matcher(ctx: import("better-auth").HookEndpointContext): true;
|
|
53
|
-
handler: (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>;
|
|
54
|
-
}[];
|
|
55
|
-
};
|
|
56
|
-
}];
|
|
57
|
-
}>;
|
|
58
|
-
/**
|
|
59
|
-
* Check if Better Auth is enabled via flag.
|
|
60
|
-
*/
|
|
61
|
-
export declare function isBetterAuthEnabled(): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Get flag-gated auth handler for Next.js route.
|
|
64
|
-
*
|
|
65
|
-
* When USE_BETTER_AUTH=true, returns Better Auth handlers.
|
|
66
|
-
* Otherwise returns null (caller uses NextAuth).
|
|
67
|
-
*
|
|
68
|
-
* Usage in host app route:
|
|
69
|
-
* ```ts
|
|
70
|
-
* import { getBetterAuthHandler } from '@payez/next-mvp/auth/better-auth';
|
|
71
|
-
*
|
|
72
|
-
* export async function GET(req: Request) {
|
|
73
|
-
* const ba = await getBetterAuthHandler();
|
|
74
|
-
* if (ba) return ba.GET(req);
|
|
75
|
-
* // ... existing NextAuth handler
|
|
76
|
-
* }
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
export declare function getBetterAuthHandler(): Promise<{
|
|
80
|
-
GET: (req: Request) => Promise<Response>;
|
|
81
|
-
POST: (req: Request) => Promise<Response>;
|
|
82
|
-
} | null>;
|
package/dist/auth/better-auth.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Better Auth Configuration (Phase 1 — parallel install)
|
|
4
|
-
*
|
|
5
|
-
* NOT wired to routes yet. Exists alongside auth-options.ts for testing.
|
|
6
|
-
* Wired in Phase 2 behind USE_BETTER_AUTH flag.
|
|
7
|
-
*
|
|
8
|
-
* Architecture: No database adapter — Better Auth runs in stateless mode
|
|
9
|
-
* with JWE cookie cache. User management stays on IDP, sessions on Redis.
|
|
10
|
-
*
|
|
11
|
-
* @see BETTER-AUTH-MIGRATION-SPEC.md
|
|
12
|
-
*/
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.buildBetterAuthProviders = buildBetterAuthProviders;
|
|
15
|
-
exports.createBetterAuthInstance = createBetterAuthInstance;
|
|
16
|
-
exports.isBetterAuthEnabled = isBetterAuthEnabled;
|
|
17
|
-
exports.getBetterAuthHandler = getBetterAuthHandler;
|
|
18
|
-
require("server-only");
|
|
19
|
-
const better_auth_1 = require("better-auth");
|
|
20
|
-
const next_js_1 = require("better-auth/next-js");
|
|
21
|
-
const next_js_2 = require("better-auth/next-js");
|
|
22
|
-
const idp_client_config_1 = require("../lib/idp-client-config");
|
|
23
|
-
/**
|
|
24
|
-
* Build Better Auth social providers from IDP config.
|
|
25
|
-
* Replaces buildOAuthProviders() from providers/oauth.ts.
|
|
26
|
-
*/
|
|
27
|
-
function buildBetterAuthProviders(config) {
|
|
28
|
-
const providers = {};
|
|
29
|
-
for (const oauth of config.oauthProviders || []) {
|
|
30
|
-
if (!oauth.enabled)
|
|
31
|
-
continue;
|
|
32
|
-
const name = oauth.provider.toLowerCase();
|
|
33
|
-
providers[name] = {
|
|
34
|
-
clientId: oauth.clientId,
|
|
35
|
-
clientSecret: oauth.clientSecret,
|
|
36
|
-
scope: oauth.scopes?.split(' '),
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return providers;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Create Better Auth instance from IDP config.
|
|
43
|
-
*
|
|
44
|
-
* No database — runs in stateless mode with JWE cookie cache.
|
|
45
|
-
* Call after getIDPClientConfig() resolves.
|
|
46
|
-
*/
|
|
47
|
-
function createBetterAuthInstance(idpConfig) {
|
|
48
|
-
return (0, better_auth_1.betterAuth)({
|
|
49
|
-
secret: idpConfig.nextAuthSecret,
|
|
50
|
-
socialProviders: buildBetterAuthProviders(idpConfig),
|
|
51
|
-
// Trust the app's own origin + any configured base URL
|
|
52
|
-
trustedOrigins: [
|
|
53
|
-
...(idpConfig.baseClientUrl ? [idpConfig.baseClientUrl] : []),
|
|
54
|
-
...(process.env.BETTER_AUTH_URL ? [process.env.BETTER_AUTH_URL] : []),
|
|
55
|
-
'http://localhost:3000',
|
|
56
|
-
'http://localhost:3400',
|
|
57
|
-
'http://localhost:3600',
|
|
58
|
-
],
|
|
59
|
-
// No database — stateless mode. Better Auth defaults to JWE cookie cache.
|
|
60
|
-
// Session cookie cache with refreshCache for DB-less setup.
|
|
61
|
-
session: {
|
|
62
|
-
cookieCache: {
|
|
63
|
-
enabled: true,
|
|
64
|
-
maxAge: 300,
|
|
65
|
-
refreshCache: true,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
plugins: [
|
|
69
|
-
(0, next_js_1.nextCookies)(),
|
|
70
|
-
],
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Check if Better Auth is enabled via flag.
|
|
75
|
-
*/
|
|
76
|
-
function isBetterAuthEnabled() {
|
|
77
|
-
return process.env.USE_BETTER_AUTH === 'true';
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Get Better Auth Next.js route handlers (GET, POST).
|
|
81
|
-
* Initializes Better Auth from IDP config on first call, caches the instance.
|
|
82
|
-
*/
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
84
|
-
let cachedInstance = null;
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
-
let initPromise = null;
|
|
87
|
-
async function getBetterAuthInstance() {
|
|
88
|
-
if (cachedInstance)
|
|
89
|
-
return cachedInstance;
|
|
90
|
-
if (!initPromise) {
|
|
91
|
-
initPromise = (0, idp_client_config_1.getIDPClientConfig)().then(config => {
|
|
92
|
-
const instance = createBetterAuthInstance(config);
|
|
93
|
-
cachedInstance = instance;
|
|
94
|
-
console.log('[BETTER_AUTH] Instance created for', config.clientSlug || config.clientId);
|
|
95
|
-
return instance;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return initPromise;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Get flag-gated auth handler for Next.js route.
|
|
102
|
-
*
|
|
103
|
-
* When USE_BETTER_AUTH=true, returns Better Auth handlers.
|
|
104
|
-
* Otherwise returns null (caller uses NextAuth).
|
|
105
|
-
*
|
|
106
|
-
* Usage in host app route:
|
|
107
|
-
* ```ts
|
|
108
|
-
* import { getBetterAuthHandler } from '@payez/next-mvp/auth/better-auth';
|
|
109
|
-
*
|
|
110
|
-
* export async function GET(req: Request) {
|
|
111
|
-
* const ba = await getBetterAuthHandler();
|
|
112
|
-
* if (ba) return ba.GET(req);
|
|
113
|
-
* // ... existing NextAuth handler
|
|
114
|
-
* }
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
async function getBetterAuthHandler() {
|
|
118
|
-
if (!isBetterAuthEnabled())
|
|
119
|
-
return null;
|
|
120
|
-
const auth = await getBetterAuthInstance();
|
|
121
|
-
return (0, next_js_2.toNextJsHandler)(auth);
|
|
122
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Auth Callbacks - Public Exports
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.signInCallback = exports.sessionCallback = exports.jwtCallback = void 0;
|
|
7
|
-
var jwt_1 = require("./jwt");
|
|
8
|
-
Object.defineProperty(exports, "jwtCallback", { enumerable: true, get: function () { return jwt_1.jwtCallback; } });
|
|
9
|
-
var session_1 = require("./session");
|
|
10
|
-
Object.defineProperty(exports, "sessionCallback", { enumerable: true, get: function () { return session_1.sessionCallback; } });
|
|
11
|
-
var signin_1 = require("./signin");
|
|
12
|
-
Object.defineProperty(exports, "signInCallback", { enumerable: true, get: function () { return signin_1.signInCallback; } });
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JWT Callback
|
|
3
|
-
*
|
|
4
|
-
* Minimal token strategy - only store redisSessionId in JWT.
|
|
5
|
-
* All session data lives in Redis, not in the browser cookie.
|
|
6
|
-
*
|
|
7
|
-
* HANDLES:
|
|
8
|
-
* - Initial sign-in (credentials): Store redisSessionId from authorize()
|
|
9
|
-
* - Initial sign-in (OAuth): Register with IDP, create session, store redisSessionId
|
|
10
|
-
* - Subsequent requests: Validate session exists, return token
|
|
11
|
-
*
|
|
12
|
-
* @version 1.0.0
|
|
13
|
-
* @since auth-refactor-2026-01
|
|
14
|
-
*/
|
|
15
|
-
import type { JWT } from 'next-auth/jwt';
|
|
16
|
-
import type { User, Account } from 'next-auth';
|
|
17
|
-
interface JwtCallbackParams {
|
|
18
|
-
token: JWT;
|
|
19
|
-
user?: User | any;
|
|
20
|
-
account?: Account | null;
|
|
21
|
-
trigger?: 'signIn' | 'signUp' | 'update';
|
|
22
|
-
}
|
|
23
|
-
interface JwtCallbackResult extends JWT {
|
|
24
|
-
/** Redis session ID - the key to look up session data */
|
|
25
|
-
redisSessionId?: string;
|
|
26
|
-
/** User ID from IDP */
|
|
27
|
-
sub: string;
|
|
28
|
-
/** Error code if session validation failed */
|
|
29
|
-
error?: string;
|
|
30
|
-
/** Flag for OAuth users who need immediate 2FA redirect */
|
|
31
|
-
requiresTwoFactorRedirect?: boolean;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* JWT callback - builds the NextAuth JWT token.
|
|
35
|
-
*
|
|
36
|
-
* MINIMAL TOKEN STRATEGY:
|
|
37
|
-
* - Only store redisSessionId (key to Redis session)
|
|
38
|
-
* - All tokens and user data live in Redis
|
|
39
|
-
* - Browser cookie stays small and secure
|
|
40
|
-
*
|
|
41
|
-
* @param params - JWT callback parameters from NextAuth
|
|
42
|
-
* @returns JWT payload to store in browser cookie
|
|
43
|
-
*/
|
|
44
|
-
export declare function jwtCallback({ token, user, account, trigger, }: JwtCallbackParams): Promise<JwtCallbackResult>;
|
|
45
|
-
export {};
|