@payez/next-mvp 4.0.1 → 4.0.3
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/dist/api/auth-handler.d.ts +66 -0
- package/dist/api/auth-handler.js +397 -0
- package/dist/api/index.d.ts +10 -0
- package/dist/api/index.js +19 -0
- package/dist/api-handlers/account/change-password.d.ts +9 -0
- package/dist/api-handlers/account/change-password.js +110 -0
- package/dist/api-handlers/account/masked-info.d.ts +2 -0
- package/dist/api-handlers/account/masked-info.js +41 -0
- package/dist/api-handlers/account/profile.d.ts +3 -0
- package/dist/api-handlers/account/profile.js +63 -0
- package/dist/api-handlers/account/recovery/initiate.d.ts +2 -0
- package/dist/api-handlers/account/recovery/initiate.js +26 -0
- package/dist/api-handlers/account/recovery/send-code.d.ts +2 -0
- package/dist/api-handlers/account/recovery/send-code.js +28 -0
- package/dist/api-handlers/account/recovery/verify-code.d.ts +2 -0
- package/dist/api-handlers/account/recovery/verify-code.js +28 -0
- package/dist/api-handlers/account/reset-password.d.ts +2 -0
- package/dist/api-handlers/account/reset-password.js +26 -0
- package/dist/api-handlers/account/send-code.d.ts +24 -0
- package/dist/api-handlers/account/send-code.js +60 -0
- package/dist/api-handlers/account/update-phone.d.ts +27 -0
- package/dist/api-handlers/account/update-phone.js +64 -0
- package/dist/api-handlers/account/validate-password.d.ts +17 -0
- package/dist/api-handlers/account/validate-password.js +81 -0
- package/dist/api-handlers/account/verify-email.d.ts +26 -0
- package/dist/api-handlers/account/verify-email.js +106 -0
- package/dist/api-handlers/account/verify-sms.d.ts +26 -0
- package/dist/api-handlers/account/verify-sms.js +106 -0
- package/dist/api-handlers/admin/analytics.d.ts +19 -0
- package/dist/api-handlers/admin/analytics.js +378 -0
- package/dist/api-handlers/admin/audit.d.ts +19 -0
- package/dist/api-handlers/admin/audit.js +213 -0
- package/dist/api-handlers/admin/index.d.ts +21 -0
- package/dist/api-handlers/admin/index.js +42 -0
- package/dist/api-handlers/admin/redis-sessions.d.ts +35 -0
- package/dist/api-handlers/admin/redis-sessions.js +203 -0
- package/dist/api-handlers/admin/sessions.d.ts +20 -0
- package/dist/api-handlers/admin/sessions.js +283 -0
- package/dist/api-handlers/admin/site-logs.d.ts +45 -0
- package/dist/api-handlers/admin/site-logs.js +317 -0
- package/dist/api-handlers/admin/stats.d.ts +20 -0
- package/dist/api-handlers/admin/stats.js +239 -0
- package/dist/api-handlers/admin/users.d.ts +19 -0
- package/dist/api-handlers/admin/users.js +221 -0
- package/dist/api-handlers/admin/vibe-data.d.ts +79 -0
- package/dist/api-handlers/admin/vibe-data.js +267 -0
- package/dist/api-handlers/anon/preferences.d.ts +37 -0
- package/dist/api-handlers/anon/preferences.js +96 -0
- package/dist/api-handlers/auth/jwks.d.ts +2 -0
- package/dist/api-handlers/auth/jwks.js +24 -0
- package/dist/api-handlers/auth/login.d.ts +42 -0
- package/dist/api-handlers/auth/login.js +178 -0
- package/dist/api-handlers/auth/refresh.d.ts +74 -0
- package/dist/api-handlers/auth/refresh.js +633 -0
- package/dist/api-handlers/auth/signout.d.ts +37 -0
- package/dist/api-handlers/auth/signout.js +186 -0
- package/dist/api-handlers/auth/status.d.ts +8 -0
- package/dist/api-handlers/auth/status.js +23 -0
- package/dist/api-handlers/auth/update-session.d.ts +37 -0
- package/dist/api-handlers/auth/update-session.js +93 -0
- package/dist/api-handlers/auth/validate.d.ts +6 -0
- package/dist/api-handlers/auth/validate.js +43 -0
- package/dist/api-handlers/auth/verify-code.d.ts +43 -0
- package/dist/api-handlers/auth/verify-code.js +90 -0
- package/dist/api-handlers/session/refresh-viability.d.ts +14 -0
- package/dist/api-handlers/session/refresh-viability.js +39 -0
- package/dist/api-handlers/session/viability.d.ts +13 -0
- package/dist/api-handlers/session/viability.js +114 -0
- package/dist/api-handlers/test/force-expire.d.ts +23 -0
- package/dist/api-handlers/test/force-expire.js +59 -0
- package/dist/auth/auth-decision.d.ts +39 -0
- package/dist/auth/auth-decision.js +182 -0
- package/dist/auth/better-auth.d.ts +79 -0
- package/dist/auth/better-auth.js +119 -0
- package/dist/auth/route-config.d.ts +66 -0
- package/dist/auth/route-config.js +190 -0
- package/dist/auth/types/auth-types.d.ts +417 -0
- package/dist/auth/types/auth-types.js +53 -0
- package/dist/auth/types/index.d.ts +6 -0
- package/dist/auth/types/index.js +22 -0
- package/dist/auth/unauthenticated-routes.d.ts +1 -0
- package/dist/auth/unauthenticated-routes.js +19 -0
- package/dist/auth/utils/idp-client.d.ts +94 -0
- package/dist/auth/utils/idp-client.js +384 -0
- package/dist/auth/utils/index.d.ts +5 -0
- package/dist/auth/utils/index.js +21 -0
- package/dist/auth/utils/token-utils.d.ts +83 -0
- package/dist/auth/utils/token-utils.js +218 -0
- package/dist/client/AuthContext.d.ts +19 -0
- package/dist/client/AuthContext.js +115 -0
- package/dist/client/better-auth-client.d.ts +1020 -0
- package/dist/client/better-auth-client.js +68 -0
- package/dist/client/fetch-with-auth.d.ts +11 -0
- package/dist/client/fetch-with-auth.js +44 -0
- package/dist/client/fetchWithSession.d.ts +3 -0
- package/dist/client/fetchWithSession.js +24 -0
- package/dist/client/index.d.ts +9 -0
- package/dist/client/index.js +20 -0
- package/dist/client/useAnonSession.d.ts +36 -0
- package/dist/client/useAnonSession.js +99 -0
- package/dist/components/SessionSync.d.ts +13 -0
- package/dist/components/SessionSync.js +121 -0
- package/dist/components/SignalRHealthCheck.d.ts +10 -0
- package/dist/components/SignalRHealthCheck.js +97 -0
- package/dist/components/account/MobileNavDrawer.d.ts +32 -0
- package/dist/components/account/MobileNavDrawer.js +81 -0
- package/dist/components/account/UserAvatarMenu.d.ts +20 -0
- package/dist/components/account/UserAvatarMenu.js +91 -0
- package/dist/components/account/index.d.ts +9 -0
- package/dist/components/account/index.js +13 -0
- package/dist/components/admin/AlertSettingsTab.d.ts +48 -0
- package/dist/components/admin/AlertSettingsTab.js +351 -0
- package/dist/components/admin/AnalyticsTab.d.ts +22 -0
- package/dist/components/admin/AnalyticsTab.js +167 -0
- package/dist/components/admin/DataBrowserTab.d.ts +19 -0
- package/dist/components/admin/DataBrowserTab.js +252 -0
- package/dist/components/admin/LoggingSettingsTab.d.ts +73 -0
- package/dist/components/admin/LoggingSettingsTab.js +339 -0
- package/dist/components/admin/SessionsTab.d.ts +37 -0
- package/dist/components/admin/SessionsTab.js +165 -0
- package/dist/components/admin/StatsTab.d.ts +53 -0
- package/dist/components/admin/StatsTab.js +161 -0
- package/dist/components/admin/VibeAdminContext.d.ts +32 -0
- package/dist/components/admin/VibeAdminContext.js +38 -0
- package/dist/components/admin/VibeAdminLayout.d.ts +11 -0
- package/dist/components/admin/VibeAdminLayout.js +71 -0
- package/dist/components/admin/index.d.ts +29 -0
- package/dist/components/admin/index.js +44 -0
- package/dist/components/auth/FederatedAuthSection.d.ts +8 -0
- package/dist/components/auth/FederatedAuthSection.js +45 -0
- package/dist/components/auth/ModeAwareLoginPage.d.ts +10 -0
- package/dist/components/auth/ModeAwareLoginPage.js +42 -0
- package/dist/components/auth/ModeAwareSignupPage.d.ts +9 -0
- package/dist/components/auth/ModeAwareSignupPage.js +78 -0
- package/dist/components/auth/TraditionalAuthSection.d.ts +14 -0
- package/dist/components/auth/TraditionalAuthSection.js +20 -0
- package/dist/components/recovery/CompleteStep.d.ts +5 -0
- package/dist/components/recovery/CompleteStep.js +8 -0
- package/dist/components/recovery/InitiateRecoveryStep.d.ts +8 -0
- package/dist/components/recovery/InitiateRecoveryStep.js +20 -0
- package/dist/components/recovery/SelectMethodStep.d.ts +8 -0
- package/dist/components/recovery/SelectMethodStep.js +8 -0
- package/dist/components/recovery/SetPasswordStep.d.ts +6 -0
- package/dist/components/recovery/SetPasswordStep.js +20 -0
- package/dist/components/recovery/VerifyCodeStep.d.ts +10 -0
- package/dist/components/recovery/VerifyCodeStep.js +24 -0
- package/dist/components/reserved/ReservedRecoveryWarning.d.ts +38 -0
- package/dist/components/reserved/ReservedRecoveryWarning.js +92 -0
- package/dist/components/reserved/ReservedStatusBox.d.ts +30 -0
- package/dist/components/reserved/ReservedStatusBox.js +71 -0
- package/dist/components/ui/BetaBadge.d.ts +29 -0
- package/dist/components/ui/BetaBadge.js +38 -0
- package/dist/components/ui/Footer.d.ts +37 -0
- package/dist/components/ui/Footer.js +41 -0
- package/dist/config/env.d.ts +66 -0
- package/dist/config/env.js +57 -0
- package/dist/config/logger.d.ts +57 -0
- package/dist/config/logger.js +73 -0
- package/dist/config/logging-config.d.ts +30 -0
- package/dist/config/logging-config.js +122 -0
- package/dist/config/unauthenticated-routes.d.ts +17 -0
- package/dist/config/unauthenticated-routes.js +24 -0
- package/dist/config/vibe-log-transport.d.ts +81 -0
- package/dist/config/vibe-log-transport.js +212 -0
- package/dist/edge/internal-api-url.d.ts +53 -0
- package/dist/edge/internal-api-url.js +63 -0
- package/dist/edge/middleware.d.ts +14 -0
- package/dist/edge/middleware.js +32 -0
- package/dist/hooks/useAuth.d.ts +23 -0
- package/dist/hooks/useAuth.js +83 -0
- package/dist/hooks/useAuthSettings.d.ts +59 -0
- package/dist/hooks/useAuthSettings.js +93 -0
- package/dist/hooks/useAvailableProviders.d.ts +43 -0
- package/dist/hooks/useAvailableProviders.js +112 -0
- package/dist/hooks/usePasswordValidation.d.ts +27 -0
- package/dist/hooks/usePasswordValidation.js +102 -0
- package/dist/hooks/useProfile.d.ts +15 -0
- package/dist/hooks/useProfile.js +59 -0
- package/dist/hooks/usePublicAuthSettings.d.ts +56 -0
- package/dist/hooks/usePublicAuthSettings.js +131 -0
- package/dist/hooks/useSessionExpiration.d.ts +56 -0
- package/dist/hooks/useSessionExpiration.js +72 -0
- package/dist/hooks/useViabilitySession.d.ts +75 -0
- package/dist/hooks/useViabilitySession.js +269 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +53 -0
- package/dist/lib/anon-session.d.ts +74 -0
- package/dist/lib/anon-session.js +169 -0
- package/dist/lib/api-handler.d.ts +123 -0
- package/dist/lib/api-handler.js +478 -0
- package/dist/lib/app-slug.d.ts +95 -0
- package/dist/lib/app-slug.js +172 -0
- package/dist/lib/demo-mode.d.ts +6 -0
- package/dist/lib/demo-mode.js +16 -0
- package/dist/lib/geolocation.d.ts +64 -0
- package/dist/lib/geolocation.js +235 -0
- package/dist/lib/idp-client-config.d.ts +75 -0
- package/dist/lib/idp-client-config.js +425 -0
- package/dist/lib/idp-fetch.d.ts +14 -0
- package/dist/lib/idp-fetch.js +91 -0
- package/dist/lib/internal-api.d.ts +87 -0
- package/dist/lib/internal-api.js +122 -0
- package/dist/lib/jwt-decode-client.d.ts +10 -0
- package/dist/lib/jwt-decode-client.js +46 -0
- package/dist/lib/jwt-decode.d.ts +48 -0
- package/dist/lib/jwt-decode.js +57 -0
- package/dist/lib/rate-limit-service.d.ts +23 -0
- package/dist/lib/rate-limit-service.js +6 -0
- package/dist/lib/redis.d.ts +5 -0
- package/dist/lib/redis.js +28 -0
- package/dist/lib/refresh-token-validator.d.ts +13 -0
- package/dist/lib/refresh-token-validator.js +117 -0
- package/dist/lib/roles.d.ts +145 -0
- package/dist/lib/roles.js +168 -0
- package/dist/lib/secret-validation.d.ts +4 -0
- package/dist/lib/secret-validation.js +14 -0
- package/dist/lib/session-store.d.ts +170 -0
- package/dist/lib/session-store.js +545 -0
- package/dist/lib/session.d.ts +21 -0
- package/dist/lib/session.js +26 -0
- package/dist/lib/site-logger.d.ts +214 -0
- package/dist/lib/site-logger.js +210 -0
- package/dist/lib/standardized-client-api.d.ts +161 -0
- package/dist/lib/standardized-client-api.js +791 -0
- package/dist/lib/startup-init.d.ts +40 -0
- package/dist/lib/startup-init.js +257 -0
- package/dist/lib/test-aware-get-token.d.ts +2 -0
- package/dist/lib/test-aware-get-token.js +86 -0
- package/dist/lib/token-expiry.d.ts +14 -0
- package/dist/lib/token-expiry.js +39 -0
- package/dist/lib/token-lifecycle.d.ts +78 -0
- package/dist/lib/token-lifecycle.js +360 -0
- package/dist/lib/types/api-responses.d.ts +128 -0
- package/dist/lib/types/api-responses.js +171 -0
- package/dist/lib/user-agent-parser.d.ts +50 -0
- package/dist/lib/user-agent-parser.js +220 -0
- package/dist/logging/api/admin-analytics.d.ts +3 -0
- package/dist/logging/api/admin-analytics.js +45 -0
- package/dist/logging/api/audit-log.d.ts +3 -0
- package/dist/logging/api/audit-log.js +52 -0
- package/dist/logging/components/AdminAnalyticsLayout.d.ts +10 -0
- package/dist/logging/components/AdminAnalyticsLayout.js +11 -0
- package/dist/logging/components/AuditLogViewer.d.ts +7 -0
- package/dist/logging/components/AuditLogViewer.js +51 -0
- package/dist/logging/components/ErrorMetricsCard.d.ts +7 -0
- package/dist/logging/components/ErrorMetricsCard.js +16 -0
- package/dist/logging/components/HealthMetricsCard.d.ts +7 -0
- package/dist/logging/components/HealthMetricsCard.js +19 -0
- package/dist/logging/hooks/useAdminAnalytics.d.ts +24 -0
- package/dist/logging/hooks/useAdminAnalytics.js +22 -0
- package/dist/logging/hooks/useAuditLog.d.ts +6 -0
- package/dist/logging/hooks/useAuditLog.js +25 -0
- package/dist/logging/hooks/useErrorMetrics.d.ts +6 -0
- package/dist/logging/hooks/useErrorMetrics.js +38 -0
- package/dist/logging/hooks/useHealthMetrics.d.ts +6 -0
- package/dist/logging/hooks/useHealthMetrics.js +41 -0
- package/dist/logging/index.d.ts +11 -0
- package/dist/logging/index.js +40 -0
- package/dist/logging/types/analytics.d.ts +68 -0
- package/dist/logging/types/analytics.js +3 -0
- package/dist/logging/types/audit.d.ts +29 -0
- package/dist/logging/types/audit.js +2 -0
- package/dist/logging/types/index.d.ts +2 -0
- package/dist/logging/types/index.js +19 -0
- package/dist/middleware/auth-decision.d.ts +33 -0
- package/dist/middleware/auth-decision.js +65 -0
- package/dist/middleware/create-middleware.d.ts +102 -0
- package/dist/middleware/create-middleware.js +469 -0
- package/dist/middleware/rbac-check.d.ts +51 -0
- package/dist/middleware/rbac-check.js +219 -0
- package/dist/middleware/twofa-presets.d.ts +134 -0
- package/dist/middleware/twofa-presets.js +175 -0
- package/dist/models/DecodedAccessToken.d.ts +17 -0
- package/dist/models/DecodedAccessToken.js +2 -0
- package/dist/models/SessionModel.d.ts +122 -0
- package/dist/models/SessionModel.js +136 -0
- package/dist/pages/admin-login/page.d.ts +31 -0
- package/dist/pages/admin-login/page.js +73 -0
- package/dist/pages/admin-page-permissions/PagePermissionsAdminPage.d.ts +18 -0
- package/dist/pages/admin-page-permissions/PagePermissionsAdminPage.js +276 -0
- package/dist/pages/admin-page-permissions/index.d.ts +6 -0
- package/dist/pages/admin-page-permissions/index.js +13 -0
- package/dist/pages/admin-roles/RolesAdminPage.d.ts +16 -0
- package/dist/pages/admin-roles/RolesAdminPage.js +261 -0
- package/dist/pages/admin-roles/index.d.ts +8 -0
- package/dist/pages/admin-roles/index.js +15 -0
- package/dist/pages/admin-roles/modals.d.ts +72 -0
- package/dist/pages/admin-roles/modals.js +154 -0
- package/dist/pages/client-admin/ClientSiteAdminPage.d.ts +79 -0
- package/dist/pages/client-admin/ClientSiteAdminPage.js +179 -0
- package/dist/pages/client-admin/index.d.ts +32 -0
- package/dist/pages/client-admin/index.js +37 -0
- package/dist/pages/coming-soon/page.d.ts +8 -0
- package/dist/pages/coming-soon/page.js +28 -0
- package/dist/pages/login/page.d.ts +22 -0
- package/dist/pages/login/page.js +230 -0
- package/dist/pages/profile/EnhancedProfilePage.d.ts +13 -0
- package/dist/pages/profile/EnhancedProfilePage.js +150 -0
- package/dist/pages/profile/index.d.ts +8 -0
- package/dist/pages/profile/index.js +16 -0
- package/dist/pages/profile/page.d.ts +19 -0
- package/dist/pages/profile/page.js +47 -0
- package/dist/pages/recovery/page.d.ts +1 -0
- package/dist/pages/recovery/page.js +142 -0
- package/dist/pages/roles/MyRolesPage.d.ts +24 -0
- package/dist/pages/roles/MyRolesPage.js +71 -0
- package/dist/pages/roles/components.d.ts +63 -0
- package/dist/pages/roles/components.js +108 -0
- package/dist/pages/roles/index.d.ts +8 -0
- package/dist/pages/roles/index.js +19 -0
- package/dist/pages/security/EnhancedSecurityPage.d.ts +14 -0
- package/dist/pages/security/EnhancedSecurityPage.js +248 -0
- package/dist/pages/security/index.d.ts +8 -0
- package/dist/pages/security/index.js +16 -0
- package/dist/pages/security/page.d.ts +21 -0
- package/dist/pages/security/page.js +212 -0
- package/dist/pages/settings/EnhancedSettingsPage.d.ts +46 -0
- package/dist/pages/settings/EnhancedSettingsPage.js +231 -0
- package/dist/pages/settings/index.d.ts +8 -0
- package/dist/pages/settings/index.js +16 -0
- package/dist/pages/settings/page.d.ts +7 -0
- package/dist/pages/settings/page.js +26 -0
- package/dist/pages/showcase/ShowcasePage.d.ts +13 -0
- package/dist/pages/showcase/ShowcasePage.js +142 -0
- package/dist/pages/showcase/index.d.ts +12 -0
- package/dist/pages/showcase/index.js +17 -0
- package/dist/pages/test-env/EmergencyLogoutPage.d.ts +14 -0
- package/dist/pages/test-env/EmergencyLogoutPage.js +99 -0
- package/dist/pages/test-env/JwtInspectPage.d.ts +14 -0
- package/dist/pages/test-env/JwtInspectPage.js +116 -0
- package/dist/pages/test-env/RefreshTokenPage.d.ts +15 -0
- package/dist/pages/test-env/RefreshTokenPage.js +93 -0
- package/dist/pages/test-env/TestEnvPage.d.ts +13 -0
- package/dist/pages/test-env/TestEnvPage.js +51 -0
- package/dist/pages/test-env/index.d.ts +24 -0
- package/dist/pages/test-env/index.js +32 -0
- package/dist/pages/verify-code/page.d.ts +30 -0
- package/dist/pages/verify-code/page.js +412 -0
- package/dist/routes/account/index.d.ts +28 -0
- package/dist/routes/account/index.js +71 -0
- package/dist/routes/account/masked-info.d.ts +33 -0
- package/dist/routes/account/masked-info.js +39 -0
- package/dist/routes/account/send-code.d.ts +37 -0
- package/dist/routes/account/send-code.js +42 -0
- package/dist/routes/account/update-phone.d.ts +13 -0
- package/dist/routes/account/update-phone.js +17 -0
- package/dist/routes/account/verify-email.d.ts +38 -0
- package/dist/routes/account/verify-email.js +43 -0
- package/dist/routes/account/verify-sms.d.ts +38 -0
- package/dist/routes/account/verify-sms.js +43 -0
- package/dist/routes/auth/index.d.ts +19 -0
- package/dist/routes/auth/index.js +64 -0
- package/dist/routes/auth/logout.d.ts +31 -0
- package/dist/routes/auth/logout.js +98 -0
- package/dist/routes/auth/nextauth.d.ts +22 -0
- package/dist/routes/auth/nextauth.js +40 -0
- package/dist/routes/auth/refresh.d.ts +30 -0
- package/dist/routes/auth/refresh.js +51 -0
- package/dist/routes/auth/session.d.ts +43 -0
- package/dist/routes/auth/session.js +157 -0
- package/dist/routes/auth/settings.d.ts +25 -0
- package/dist/routes/auth/settings.js +55 -0
- package/dist/routes/auth/viability.d.ts +52 -0
- package/dist/routes/auth/viability.js +190 -0
- package/dist/routes/index.d.ts +12 -0
- package/dist/routes/index.js +54 -0
- package/dist/routes/session/index.d.ts +6 -0
- package/dist/routes/session/index.js +10 -0
- package/dist/routes/session/refresh-viability.d.ts +16 -0
- package/dist/routes/session/refresh-viability.js +20 -0
- package/dist/server/auth-guard.d.ts +46 -0
- package/dist/server/auth-guard.js +128 -0
- package/dist/server/auth.d.ts +50 -0
- package/dist/server/auth.js +62 -0
- package/dist/server/decode-session.d.ts +30 -0
- package/dist/server/decode-session.js +78 -0
- package/dist/server/slim-middleware.d.ts +23 -0
- package/dist/server/slim-middleware.js +89 -0
- package/dist/server/with-auth.d.ts +33 -0
- package/dist/server/with-auth.js +59 -0
- package/dist/services/signalrActivityService.d.ts +44 -0
- package/dist/services/signalrActivityService.js +257 -0
- package/dist/stores/authStore.d.ts +154 -0
- package/dist/stores/authStore.js +1527 -0
- package/dist/theme/ThemeProvider.d.ts +14 -0
- package/dist/theme/ThemeProvider.js +28 -0
- package/dist/theme/default.d.ts +8 -0
- package/dist/theme/default.js +33 -0
- package/dist/theme/index.d.ts +15 -0
- package/dist/theme/index.js +25 -0
- package/dist/theme/types.d.ts +56 -0
- package/dist/theme/types.js +8 -0
- package/dist/theme/useTheme.d.ts +60 -0
- package/dist/theme/useTheme.js +63 -0
- package/dist/theme/utils.d.ts +13 -0
- package/dist/theme/utils.js +39 -0
- package/dist/types/api.d.ts +134 -0
- package/dist/types/api.js +44 -0
- package/dist/types/auth.d.ts +19 -0
- package/dist/types/auth.js +2 -0
- package/dist/types/logging.d.ts +42 -0
- package/dist/types/logging.js +2 -0
- package/dist/types/recovery.d.ts +48 -0
- package/dist/types/recovery.js +2 -0
- package/dist/types/security.d.ts +1 -0
- package/dist/types/security.js +2 -0
- package/dist/utils/api.d.ts +85 -0
- package/dist/utils/api.js +287 -0
- package/dist/utils/circuitBreaker.d.ts +43 -0
- package/dist/utils/circuitBreaker.js +91 -0
- package/dist/utils/error-message.d.ts +1 -0
- package/dist/utils/error-message.js +103 -0
- package/dist/utils/layout/reservedSpace.d.ts +59 -0
- package/dist/utils/layout/reservedSpace.js +102 -0
- package/dist/utils/logout.d.ts +14 -0
- package/dist/utils/logout.js +32 -0
- package/dist/vibe/client.d.ts +261 -0
- package/dist/vibe/client.js +445 -0
- package/dist/vibe/enterprise-auth.d.ts +106 -0
- package/dist/vibe/enterprise-auth.js +173 -0
- package/dist/vibe/errors.d.ts +83 -0
- package/dist/vibe/errors.js +146 -0
- package/dist/vibe/generic.d.ts +234 -0
- package/dist/vibe/generic.js +369 -0
- package/dist/vibe/hooks/index.d.ts +169 -0
- package/dist/vibe/hooks/index.js +252 -0
- package/dist/vibe/index.d.ts +25 -0
- package/dist/vibe/index.js +72 -0
- package/dist/vibe/sessions.d.ts +161 -0
- package/dist/vibe/sessions.js +391 -0
- package/dist/vibe/types.d.ts +353 -0
- package/dist/vibe/types.js +315 -0
- package/package.json +1 -1
- package/src/auth/better-auth.ts +2 -2
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* useAvailableProviders Hook
|
|
4
|
+
*
|
|
5
|
+
* Fetches the list of OAuth providers actually configured in NextAuth.
|
|
6
|
+
* This ensures UI only shows buttons for providers that are enabled in IDP.
|
|
7
|
+
*/
|
|
8
|
+
'use client';
|
|
9
|
+
/**
|
|
10
|
+
* useAvailableProviders Hook
|
|
11
|
+
*
|
|
12
|
+
* Fetches the list of OAuth providers actually configured in NextAuth.
|
|
13
|
+
* This ensures UI only shows buttons for providers that are enabled in IDP.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.useAvailableProviders = useAvailableProviders;
|
|
17
|
+
exports.useIsProviderAvailable = useIsProviderAvailable;
|
|
18
|
+
const react_1 = require("react");
|
|
19
|
+
// Map NextAuth provider IDs to our FederatedProvider type
|
|
20
|
+
const PROVIDER_MAP = {
|
|
21
|
+
'google': 'google',
|
|
22
|
+
'apple': 'apple',
|
|
23
|
+
'facebook': 'facebook',
|
|
24
|
+
'github': 'github',
|
|
25
|
+
'azure-ad': 'microsoft',
|
|
26
|
+
'microsoft-entra-id': 'microsoft',
|
|
27
|
+
};
|
|
28
|
+
// Providers we support in UI (excludes credentials)
|
|
29
|
+
const OAUTH_PROVIDERS = ['google', 'apple', 'facebook', 'github', 'azure-ad', 'microsoft-entra-id'];
|
|
30
|
+
/**
|
|
31
|
+
* Hook to get available OAuth providers from NextAuth.
|
|
32
|
+
*
|
|
33
|
+
* Returns only the providers that are actually configured in auth-options,
|
|
34
|
+
* which reflects what's enabled in IDP config.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```tsx
|
|
38
|
+
* function SignupPage() {
|
|
39
|
+
* const { providers, isLoading } = useAvailableProviders();
|
|
40
|
+
*
|
|
41
|
+
* if (isLoading) return <Spinner />;
|
|
42
|
+
*
|
|
43
|
+
* return (
|
|
44
|
+
* <FederatedAuthSection
|
|
45
|
+
* providers={providers}
|
|
46
|
+
* onProviderClick={handleClick}
|
|
47
|
+
* />
|
|
48
|
+
* );
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
function useAvailableProviders() {
|
|
53
|
+
const [providers, setProviders] = (0, react_1.useState)([]);
|
|
54
|
+
const [rawProviders, setRawProviders] = (0, react_1.useState)(null);
|
|
55
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
56
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
57
|
+
(0, react_1.useEffect)(() => {
|
|
58
|
+
let mounted = true;
|
|
59
|
+
async function fetchProviders() {
|
|
60
|
+
try {
|
|
61
|
+
// Fetch available providers from Better Auth
|
|
62
|
+
// Better Auth doesn't have a getProviders equivalent, so we use a static list
|
|
63
|
+
// based on configured social providers
|
|
64
|
+
const result = {
|
|
65
|
+
google: { id: 'google', name: 'Google' },
|
|
66
|
+
};
|
|
67
|
+
if (!mounted)
|
|
68
|
+
return;
|
|
69
|
+
setRawProviders(result);
|
|
70
|
+
if (result) {
|
|
71
|
+
// Filter to OAuth providers only (exclude credentials)
|
|
72
|
+
// Map to our FederatedProvider type
|
|
73
|
+
const oauthProviders = Object.keys(result)
|
|
74
|
+
.filter(id => OAUTH_PROVIDERS.includes(id))
|
|
75
|
+
.map(id => PROVIDER_MAP[id])
|
|
76
|
+
.filter((p) => p !== undefined);
|
|
77
|
+
setProviders(oauthProviders);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
setProviders([]);
|
|
81
|
+
}
|
|
82
|
+
setError(null);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
if (!mounted)
|
|
86
|
+
return;
|
|
87
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
88
|
+
setProviders([]);
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
if (mounted) {
|
|
92
|
+
setIsLoading(false);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
fetchProviders();
|
|
97
|
+
return () => {
|
|
98
|
+
mounted = false;
|
|
99
|
+
};
|
|
100
|
+
}, []);
|
|
101
|
+
return { providers, isLoading, error, rawProviders };
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Check if a specific provider is available.
|
|
105
|
+
*
|
|
106
|
+
* @param provider The provider to check
|
|
107
|
+
* @returns boolean indicating if provider is configured
|
|
108
|
+
*/
|
|
109
|
+
function useIsProviderAvailable(provider) {
|
|
110
|
+
const { providers } = useAvailableProviders();
|
|
111
|
+
return providers.includes(provider);
|
|
112
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Password Validation Hook for @payez/next-mvp
|
|
3
|
+
*
|
|
4
|
+
* Provides real-time password validation against IDP password policy.
|
|
5
|
+
* Uses debounced API calls to validate password strength.
|
|
6
|
+
*/
|
|
7
|
+
interface PasswordPolicy {
|
|
8
|
+
min_length?: number;
|
|
9
|
+
require_uppercase?: boolean;
|
|
10
|
+
require_lowercase?: boolean;
|
|
11
|
+
require_digit?: boolean;
|
|
12
|
+
require_special?: boolean;
|
|
13
|
+
min_strength_score?: number;
|
|
14
|
+
}
|
|
15
|
+
interface UsePasswordValidationOptions {
|
|
16
|
+
debounceMs?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function usePasswordValidation(options?: UsePasswordValidationOptions): {
|
|
19
|
+
setPassword: (password: string) => void;
|
|
20
|
+
isValid: boolean;
|
|
21
|
+
score: number;
|
|
22
|
+
failedRequirements: string[];
|
|
23
|
+
tip: string | undefined;
|
|
24
|
+
policy: PasswordPolicy | undefined;
|
|
25
|
+
isValidating: boolean;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Password Validation Hook for @payez/next-mvp
|
|
4
|
+
*
|
|
5
|
+
* Provides real-time password validation against IDP password policy.
|
|
6
|
+
* Uses debounced API calls to validate password strength.
|
|
7
|
+
*/
|
|
8
|
+
'use client';
|
|
9
|
+
/**
|
|
10
|
+
* Password Validation Hook for @payez/next-mvp
|
|
11
|
+
*
|
|
12
|
+
* Provides real-time password validation against IDP password policy.
|
|
13
|
+
* Uses debounced API calls to validate password strength.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.usePasswordValidation = usePasswordValidation;
|
|
17
|
+
const react_1 = require("react");
|
|
18
|
+
function usePasswordValidation(options = {}) {
|
|
19
|
+
const { debounceMs = 300 } = options;
|
|
20
|
+
const [isValid, setIsValid] = (0, react_1.useState)(false);
|
|
21
|
+
const [score, setScore] = (0, react_1.useState)(0);
|
|
22
|
+
const [failedRequirements, setFailedRequirements] = (0, react_1.useState)([]);
|
|
23
|
+
const [tip, setTip] = (0, react_1.useState)(undefined);
|
|
24
|
+
const [policy, setPolicy] = (0, react_1.useState)(undefined);
|
|
25
|
+
const [isValidating, setIsValidating] = (0, react_1.useState)(false);
|
|
26
|
+
const debounceTimerRef = (0, react_1.useRef)(null);
|
|
27
|
+
const abortControllerRef = (0, react_1.useRef)(null);
|
|
28
|
+
const validatePassword = (0, react_1.useCallback)(async (password) => {
|
|
29
|
+
// Cancel any pending request
|
|
30
|
+
if (abortControllerRef.current) {
|
|
31
|
+
abortControllerRef.current.abort();
|
|
32
|
+
}
|
|
33
|
+
// Don't validate empty passwords
|
|
34
|
+
if (!password || password.length === 0) {
|
|
35
|
+
setIsValid(false);
|
|
36
|
+
setScore(0);
|
|
37
|
+
setFailedRequirements([]);
|
|
38
|
+
setTip(undefined);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setIsValidating(true);
|
|
42
|
+
abortControllerRef.current = new AbortController();
|
|
43
|
+
try {
|
|
44
|
+
const response = await fetch('/api/account/validate-password', {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: { 'Content-Type': 'application/json' },
|
|
47
|
+
body: JSON.stringify({ password }),
|
|
48
|
+
signal: abortControllerRef.current.signal,
|
|
49
|
+
});
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
setIsValid(data.is_valid);
|
|
52
|
+
setScore(data.score);
|
|
53
|
+
setFailedRequirements(data.failed_requirements || []);
|
|
54
|
+
setTip(data.tip);
|
|
55
|
+
if (data.policy) {
|
|
56
|
+
setPolicy(data.policy);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
if (err.name !== 'AbortError') {
|
|
61
|
+
console.error('[usePasswordValidation] Error:', err);
|
|
62
|
+
// On error, assume invalid but don't block user
|
|
63
|
+
setIsValid(false);
|
|
64
|
+
setScore(0);
|
|
65
|
+
setFailedRequirements(['Unable to validate password']);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
setIsValidating(false);
|
|
70
|
+
}
|
|
71
|
+
}, []);
|
|
72
|
+
const setPassword = (0, react_1.useCallback)((password) => {
|
|
73
|
+
// Clear any pending debounce
|
|
74
|
+
if (debounceTimerRef.current) {
|
|
75
|
+
clearTimeout(debounceTimerRef.current);
|
|
76
|
+
}
|
|
77
|
+
// Debounce the validation
|
|
78
|
+
debounceTimerRef.current = setTimeout(() => {
|
|
79
|
+
validatePassword(password);
|
|
80
|
+
}, debounceMs);
|
|
81
|
+
}, [debounceMs, validatePassword]);
|
|
82
|
+
// Cleanup on unmount
|
|
83
|
+
(0, react_1.useEffect)(() => {
|
|
84
|
+
return () => {
|
|
85
|
+
if (debounceTimerRef.current) {
|
|
86
|
+
clearTimeout(debounceTimerRef.current);
|
|
87
|
+
}
|
|
88
|
+
if (abortControllerRef.current) {
|
|
89
|
+
abortControllerRef.current.abort();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}, []);
|
|
93
|
+
return {
|
|
94
|
+
setPassword,
|
|
95
|
+
isValid,
|
|
96
|
+
score,
|
|
97
|
+
failedRequirements,
|
|
98
|
+
tip,
|
|
99
|
+
policy,
|
|
100
|
+
isValidating,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type ProfileResponse = {
|
|
2
|
+
email: string;
|
|
3
|
+
user_id?: string;
|
|
4
|
+
first_name?: string;
|
|
5
|
+
last_name?: string;
|
|
6
|
+
full_name?: string;
|
|
7
|
+
phone_number?: string;
|
|
8
|
+
email_confirmed?: boolean;
|
|
9
|
+
phone_confirmed?: boolean;
|
|
10
|
+
two_factor_enabled?: boolean;
|
|
11
|
+
roles?: string[];
|
|
12
|
+
contact_information?: Record<string, any>;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
export declare function useProfile(): import("@tanstack/react-query").UseQueryResult<ProfileResponse, Error>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useProfile = useProfile;
|
|
5
|
+
/**
|
|
6
|
+
* ⚠️ WARNING: This hook cannot be used directly from the @payez/next-mvp package!
|
|
7
|
+
*
|
|
8
|
+
* @deprecated Import this hook from your local app instead
|
|
9
|
+
*
|
|
10
|
+
* **Why?** This hook depends on useAuth, which requires SessionProvider context that cannot cross package boundaries.
|
|
11
|
+
*
|
|
12
|
+
* **Solution:** Create a local version in your app (e.g., src/hooks/useProfile.ts):
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // src/hooks/useProfile.ts (YOUR APP)
|
|
17
|
+
* 'use client';
|
|
18
|
+
* import { useQuery } from '@tanstack/react-query';
|
|
19
|
+
* import { useAuth } from './useAuth'; // Your local useAuth
|
|
20
|
+
* import { isApiSuccess } from '@payez/next-mvp/lib/standardized-client-api';
|
|
21
|
+
*
|
|
22
|
+
* export function useProfile() {
|
|
23
|
+
* const { isAuthenticated, apiCall } = useAuth();
|
|
24
|
+
* return useQuery({
|
|
25
|
+
* queryKey: ['account', 'profile'],
|
|
26
|
+
* enabled: isAuthenticated,
|
|
27
|
+
* queryFn: async () => {
|
|
28
|
+
* const result = await apiCall('/api/account/profile', 'GET');
|
|
29
|
+
* if (isApiSuccess(result)) return result.data;
|
|
30
|
+
* throw new Error(result.message);
|
|
31
|
+
* }
|
|
32
|
+
* });
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @see {@link https://github.com/payez/next-mvp/blob/main/docs/centralized-auth-api-pattern.md#usage-patterns Complete documentation}
|
|
37
|
+
*/
|
|
38
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
39
|
+
const useAuth_1 = require("./useAuth");
|
|
40
|
+
const standardized_client_api_1 = require("../lib/standardized-client-api");
|
|
41
|
+
function useProfile() {
|
|
42
|
+
const { isAuthenticated, apiCall } = (0, useAuth_1.useAuth)();
|
|
43
|
+
return (0, react_query_1.useQuery)({
|
|
44
|
+
queryKey: ['account', 'profile'],
|
|
45
|
+
enabled: isAuthenticated,
|
|
46
|
+
queryFn: async () => {
|
|
47
|
+
const result = await apiCall('/api/account/profile', 'GET');
|
|
48
|
+
if ((0, standardized_client_api_1.isApiSuccess)(result)) {
|
|
49
|
+
return result.data;
|
|
50
|
+
}
|
|
51
|
+
// If API returned standardized error
|
|
52
|
+
if ((0, standardized_client_api_1.isApiError)(result)) {
|
|
53
|
+
throw new Error(result.message || 'Failed to load profile');
|
|
54
|
+
}
|
|
55
|
+
throw new Error('Failed to load profile');
|
|
56
|
+
},
|
|
57
|
+
staleTime: 5 * 60 * 1000,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* usePublicAuthSettings Hook
|
|
3
|
+
*
|
|
4
|
+
* Fetches public auth settings for pre-login pages (signup, login).
|
|
5
|
+
* Does NOT require authentication - settings are fetched via API.
|
|
6
|
+
*/
|
|
7
|
+
import type { FederatedProvider } from '../types/auth';
|
|
8
|
+
export interface PublicAuthSettings {
|
|
9
|
+
enabledProviders: FederatedProvider[];
|
|
10
|
+
allowPublicRegistration: boolean;
|
|
11
|
+
allowSocialLogin: boolean;
|
|
12
|
+
enablePasswordReset: boolean;
|
|
13
|
+
require2FA: boolean;
|
|
14
|
+
allowed2FAMethods: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface UsePublicAuthSettingsResult {
|
|
17
|
+
settings: PublicAuthSettings | null;
|
|
18
|
+
isLoading: boolean;
|
|
19
|
+
error: Error | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Hook to fetch public auth settings for login/signup pages.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* function SignupPage() {
|
|
27
|
+
* const { settings, isLoading } = usePublicAuthSettings();
|
|
28
|
+
*
|
|
29
|
+
* if (isLoading) return <Spinner />;
|
|
30
|
+
*
|
|
31
|
+
* return (
|
|
32
|
+
* <>
|
|
33
|
+
* {settings?.allowSocialLogin && (
|
|
34
|
+
* <FederatedAuthSection providers={settings.enabledProviders} />
|
|
35
|
+
* )}
|
|
36
|
+
* {settings?.allowPublicRegistration && (
|
|
37
|
+
* <EmailSignupForm />
|
|
38
|
+
* )}
|
|
39
|
+
* </>
|
|
40
|
+
* );
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function usePublicAuthSettings(): UsePublicAuthSettingsResult;
|
|
45
|
+
/**
|
|
46
|
+
* Hook to check if social login is enabled.
|
|
47
|
+
*/
|
|
48
|
+
export declare function useSocialLoginEnabled(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Hook to check if public registration is enabled.
|
|
51
|
+
*/
|
|
52
|
+
export declare function usePublicRegistrationEnabled(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Hook to check if password reset is enabled.
|
|
55
|
+
*/
|
|
56
|
+
export declare function usePasswordResetEnabled(): boolean;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* usePublicAuthSettings Hook
|
|
4
|
+
*
|
|
5
|
+
* Fetches public auth settings for pre-login pages (signup, login).
|
|
6
|
+
* Does NOT require authentication - settings are fetched via API.
|
|
7
|
+
*/
|
|
8
|
+
'use client';
|
|
9
|
+
/**
|
|
10
|
+
* usePublicAuthSettings Hook
|
|
11
|
+
*
|
|
12
|
+
* Fetches public auth settings for pre-login pages (signup, login).
|
|
13
|
+
* Does NOT require authentication - settings are fetched via API.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.usePublicAuthSettings = usePublicAuthSettings;
|
|
17
|
+
exports.useSocialLoginEnabled = useSocialLoginEnabled;
|
|
18
|
+
exports.usePublicRegistrationEnabled = usePublicRegistrationEnabled;
|
|
19
|
+
exports.usePasswordResetEnabled = usePasswordResetEnabled;
|
|
20
|
+
const react_1 = require("react");
|
|
21
|
+
// Map provider strings to FederatedProvider type
|
|
22
|
+
const PROVIDER_MAP = {
|
|
23
|
+
'google': 'google',
|
|
24
|
+
'apple': 'apple',
|
|
25
|
+
'facebook': 'facebook',
|
|
26
|
+
'github': 'github',
|
|
27
|
+
'microsoft': 'microsoft',
|
|
28
|
+
'azure-ad': 'microsoft',
|
|
29
|
+
};
|
|
30
|
+
const DEFAULT_SETTINGS = {
|
|
31
|
+
enabledProviders: [],
|
|
32
|
+
allowPublicRegistration: true,
|
|
33
|
+
allowSocialLogin: false,
|
|
34
|
+
enablePasswordReset: true,
|
|
35
|
+
require2FA: true,
|
|
36
|
+
allowed2FAMethods: ['email', 'sms'],
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Hook to fetch public auth settings for login/signup pages.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* function SignupPage() {
|
|
44
|
+
* const { settings, isLoading } = usePublicAuthSettings();
|
|
45
|
+
*
|
|
46
|
+
* if (isLoading) return <Spinner />;
|
|
47
|
+
*
|
|
48
|
+
* return (
|
|
49
|
+
* <>
|
|
50
|
+
* {settings?.allowSocialLogin && (
|
|
51
|
+
* <FederatedAuthSection providers={settings.enabledProviders} />
|
|
52
|
+
* )}
|
|
53
|
+
* {settings?.allowPublicRegistration && (
|
|
54
|
+
* <EmailSignupForm />
|
|
55
|
+
* )}
|
|
56
|
+
* </>
|
|
57
|
+
* );
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
function usePublicAuthSettings() {
|
|
62
|
+
const [settings, setSettings] = (0, react_1.useState)(null);
|
|
63
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
64
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
65
|
+
(0, react_1.useEffect)(() => {
|
|
66
|
+
let mounted = true;
|
|
67
|
+
async function fetchSettings() {
|
|
68
|
+
try {
|
|
69
|
+
const response = await fetch('/api/auth/settings');
|
|
70
|
+
if (!mounted)
|
|
71
|
+
return;
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
throw new Error(`Failed to fetch auth settings: ${response.status}`);
|
|
74
|
+
}
|
|
75
|
+
const data = await response.json();
|
|
76
|
+
if (data.success && data.data) {
|
|
77
|
+
// Map provider strings to FederatedProvider type
|
|
78
|
+
const providers = (data.data.enabledProviders || [])
|
|
79
|
+
.map((p) => PROVIDER_MAP[p.toLowerCase()])
|
|
80
|
+
.filter((p) => p !== undefined);
|
|
81
|
+
setSettings({
|
|
82
|
+
...data.data,
|
|
83
|
+
enabledProviders: providers,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
setSettings(DEFAULT_SETTINGS);
|
|
88
|
+
}
|
|
89
|
+
setError(null);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
if (!mounted)
|
|
93
|
+
return;
|
|
94
|
+
console.warn('[usePublicAuthSettings] Failed to fetch settings:', err);
|
|
95
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
96
|
+
setSettings(DEFAULT_SETTINGS);
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
if (mounted) {
|
|
100
|
+
setIsLoading(false);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
fetchSettings();
|
|
105
|
+
return () => {
|
|
106
|
+
mounted = false;
|
|
107
|
+
};
|
|
108
|
+
}, []);
|
|
109
|
+
return { settings, isLoading, error };
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Hook to check if social login is enabled.
|
|
113
|
+
*/
|
|
114
|
+
function useSocialLoginEnabled() {
|
|
115
|
+
const { settings } = usePublicAuthSettings();
|
|
116
|
+
return settings?.allowSocialLogin ?? false;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Hook to check if public registration is enabled.
|
|
120
|
+
*/
|
|
121
|
+
function usePublicRegistrationEnabled() {
|
|
122
|
+
const { settings } = usePublicAuthSettings();
|
|
123
|
+
return settings?.allowPublicRegistration ?? true;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Hook to check if password reset is enabled.
|
|
127
|
+
*/
|
|
128
|
+
function usePasswordResetEnabled() {
|
|
129
|
+
const { settings } = usePublicAuthSettings();
|
|
130
|
+
return settings?.enablePasswordReset ?? true;
|
|
131
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook to detect and handle stale/expired sessions during 2FA flow
|
|
3
|
+
*
|
|
4
|
+
* Use this in verify-code pages to automatically redirect to login
|
|
5
|
+
* when the provisional bearer token has expired.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { useSessionExpiration } from '@payez/next-mvp/hooks/useSessionExpiration';
|
|
10
|
+
*
|
|
11
|
+
* function VerifyCodePage() {
|
|
12
|
+
* const { data: session } = useSession();
|
|
13
|
+
* const router = useRouter();
|
|
14
|
+
* const searchParams = useSearchParams();
|
|
15
|
+
* const [error, setError] = useState<string | null>(null);
|
|
16
|
+
*
|
|
17
|
+
* const callbackUrl = searchParams?.get('callbackUrl') || '/dashboard';
|
|
18
|
+
*
|
|
19
|
+
* // Automatically handles session expiration
|
|
20
|
+
* const sessionValid = useSessionExpiration({
|
|
21
|
+
* session,
|
|
22
|
+
* router,
|
|
23
|
+
* callbackUrl,
|
|
24
|
+
* onExpired: (message) => setError(message)
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* if (!sessionValid) return null; // Will redirect
|
|
28
|
+
* // ... rest of component
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export interface UseSessionExpirationOptions {
|
|
33
|
+
/** Session object */
|
|
34
|
+
session: any | null | undefined;
|
|
35
|
+
/** Next.js router for navigation */
|
|
36
|
+
router: {
|
|
37
|
+
push: (url: string) => void;
|
|
38
|
+
};
|
|
39
|
+
/** URL to redirect to after login */
|
|
40
|
+
callbackUrl?: string;
|
|
41
|
+
/** Callback when session expires - use to set error state */
|
|
42
|
+
onExpired?: (message: string) => void;
|
|
43
|
+
/** Delay before redirect in milliseconds (default: 1500) */
|
|
44
|
+
redirectDelay?: number;
|
|
45
|
+
/** Custom redirect URL (default: /account-auth/login) */
|
|
46
|
+
loginUrl?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Detects stale sessions and redirects to login
|
|
50
|
+
*
|
|
51
|
+
* Returns:
|
|
52
|
+
* - `true` if session is valid (has accessToken)
|
|
53
|
+
* - `false` if session is loading (no session yet)
|
|
54
|
+
* - `null` if session is stale (will trigger redirect)
|
|
55
|
+
*/
|
|
56
|
+
export declare function useSessionExpiration({ session, router, callbackUrl, onExpired, redirectDelay, loginUrl }: UseSessionExpirationOptions): boolean | null;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Hook to detect and handle stale/expired sessions during 2FA flow
|
|
4
|
+
*
|
|
5
|
+
* Use this in verify-code pages to automatically redirect to login
|
|
6
|
+
* when the provisional bearer token has expired.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { useSessionExpiration } from '@payez/next-mvp/hooks/useSessionExpiration';
|
|
11
|
+
*
|
|
12
|
+
* function VerifyCodePage() {
|
|
13
|
+
* const { data: session } = useSession();
|
|
14
|
+
* const router = useRouter();
|
|
15
|
+
* const searchParams = useSearchParams();
|
|
16
|
+
* const [error, setError] = useState<string | null>(null);
|
|
17
|
+
*
|
|
18
|
+
* const callbackUrl = searchParams?.get('callbackUrl') || '/dashboard';
|
|
19
|
+
*
|
|
20
|
+
* // Automatically handles session expiration
|
|
21
|
+
* const sessionValid = useSessionExpiration({
|
|
22
|
+
* session,
|
|
23
|
+
* router,
|
|
24
|
+
* callbackUrl,
|
|
25
|
+
* onExpired: (message) => setError(message)
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* if (!sessionValid) return null; // Will redirect
|
|
29
|
+
* // ... rest of component
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.useSessionExpiration = useSessionExpiration;
|
|
35
|
+
const react_1 = require("react");
|
|
36
|
+
const better_auth_client_1 = require("../client/better-auth-client");
|
|
37
|
+
/**
|
|
38
|
+
* Detects stale sessions and redirects to login
|
|
39
|
+
*
|
|
40
|
+
* Returns:
|
|
41
|
+
* - `true` if session is valid (has accessToken)
|
|
42
|
+
* - `false` if session is loading (no session yet)
|
|
43
|
+
* - `null` if session is stale (will trigger redirect)
|
|
44
|
+
*/
|
|
45
|
+
function useSessionExpiration({ session, router, callbackUrl = '/dashboard', onExpired, redirectDelay = 1500, loginUrl = '/account-auth/login' }) {
|
|
46
|
+
(0, react_1.useEffect)(() => {
|
|
47
|
+
// If session exists but no accessToken, the token is stale/expired
|
|
48
|
+
if (session && !session.accessToken) {
|
|
49
|
+
const message = 'Your session has expired. Redirecting to login...';
|
|
50
|
+
if (onExpired) {
|
|
51
|
+
onExpired(message);
|
|
52
|
+
}
|
|
53
|
+
setTimeout(async () => {
|
|
54
|
+
// Clear the session before redirecting
|
|
55
|
+
await better_auth_client_1.authClient.signOut();
|
|
56
|
+
const params = new URLSearchParams({
|
|
57
|
+
callbackUrl,
|
|
58
|
+
error: 'SessionExpired'
|
|
59
|
+
});
|
|
60
|
+
router.push(`${loginUrl}?${params.toString()}`);
|
|
61
|
+
}, redirectDelay);
|
|
62
|
+
}
|
|
63
|
+
}, [session, router, callbackUrl, onExpired, redirectDelay, loginUrl]);
|
|
64
|
+
// Return session validity state
|
|
65
|
+
if (session && !session.accessToken) {
|
|
66
|
+
return null; // Stale session - will redirect
|
|
67
|
+
}
|
|
68
|
+
if (session?.accessToken) {
|
|
69
|
+
return true; // Valid session
|
|
70
|
+
}
|
|
71
|
+
return false; // No session yet - loading
|
|
72
|
+
}
|