@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.
Files changed (434) hide show
  1. package/dist/api/auth-handler.d.ts +66 -0
  2. package/dist/api/auth-handler.js +397 -0
  3. package/dist/api/index.d.ts +10 -0
  4. package/dist/api/index.js +19 -0
  5. package/dist/api-handlers/account/change-password.d.ts +9 -0
  6. package/dist/api-handlers/account/change-password.js +110 -0
  7. package/dist/api-handlers/account/masked-info.d.ts +2 -0
  8. package/dist/api-handlers/account/masked-info.js +41 -0
  9. package/dist/api-handlers/account/profile.d.ts +3 -0
  10. package/dist/api-handlers/account/profile.js +63 -0
  11. package/dist/api-handlers/account/recovery/initiate.d.ts +2 -0
  12. package/dist/api-handlers/account/recovery/initiate.js +26 -0
  13. package/dist/api-handlers/account/recovery/send-code.d.ts +2 -0
  14. package/dist/api-handlers/account/recovery/send-code.js +28 -0
  15. package/dist/api-handlers/account/recovery/verify-code.d.ts +2 -0
  16. package/dist/api-handlers/account/recovery/verify-code.js +28 -0
  17. package/dist/api-handlers/account/reset-password.d.ts +2 -0
  18. package/dist/api-handlers/account/reset-password.js +26 -0
  19. package/dist/api-handlers/account/send-code.d.ts +24 -0
  20. package/dist/api-handlers/account/send-code.js +60 -0
  21. package/dist/api-handlers/account/update-phone.d.ts +27 -0
  22. package/dist/api-handlers/account/update-phone.js +64 -0
  23. package/dist/api-handlers/account/validate-password.d.ts +17 -0
  24. package/dist/api-handlers/account/validate-password.js +81 -0
  25. package/dist/api-handlers/account/verify-email.d.ts +26 -0
  26. package/dist/api-handlers/account/verify-email.js +106 -0
  27. package/dist/api-handlers/account/verify-sms.d.ts +26 -0
  28. package/dist/api-handlers/account/verify-sms.js +106 -0
  29. package/dist/api-handlers/admin/analytics.d.ts +19 -0
  30. package/dist/api-handlers/admin/analytics.js +378 -0
  31. package/dist/api-handlers/admin/audit.d.ts +19 -0
  32. package/dist/api-handlers/admin/audit.js +213 -0
  33. package/dist/api-handlers/admin/index.d.ts +21 -0
  34. package/dist/api-handlers/admin/index.js +42 -0
  35. package/dist/api-handlers/admin/redis-sessions.d.ts +35 -0
  36. package/dist/api-handlers/admin/redis-sessions.js +203 -0
  37. package/dist/api-handlers/admin/sessions.d.ts +20 -0
  38. package/dist/api-handlers/admin/sessions.js +283 -0
  39. package/dist/api-handlers/admin/site-logs.d.ts +45 -0
  40. package/dist/api-handlers/admin/site-logs.js +317 -0
  41. package/dist/api-handlers/admin/stats.d.ts +20 -0
  42. package/dist/api-handlers/admin/stats.js +239 -0
  43. package/dist/api-handlers/admin/users.d.ts +19 -0
  44. package/dist/api-handlers/admin/users.js +221 -0
  45. package/dist/api-handlers/admin/vibe-data.d.ts +79 -0
  46. package/dist/api-handlers/admin/vibe-data.js +267 -0
  47. package/dist/api-handlers/anon/preferences.d.ts +37 -0
  48. package/dist/api-handlers/anon/preferences.js +96 -0
  49. package/dist/api-handlers/auth/jwks.d.ts +2 -0
  50. package/dist/api-handlers/auth/jwks.js +24 -0
  51. package/dist/api-handlers/auth/login.d.ts +42 -0
  52. package/dist/api-handlers/auth/login.js +178 -0
  53. package/dist/api-handlers/auth/refresh.d.ts +74 -0
  54. package/dist/api-handlers/auth/refresh.js +633 -0
  55. package/dist/api-handlers/auth/signout.d.ts +37 -0
  56. package/dist/api-handlers/auth/signout.js +186 -0
  57. package/dist/api-handlers/auth/status.d.ts +8 -0
  58. package/dist/api-handlers/auth/status.js +23 -0
  59. package/dist/api-handlers/auth/update-session.d.ts +37 -0
  60. package/dist/api-handlers/auth/update-session.js +93 -0
  61. package/dist/api-handlers/auth/validate.d.ts +6 -0
  62. package/dist/api-handlers/auth/validate.js +43 -0
  63. package/dist/api-handlers/auth/verify-code.d.ts +43 -0
  64. package/dist/api-handlers/auth/verify-code.js +90 -0
  65. package/dist/api-handlers/session/refresh-viability.d.ts +14 -0
  66. package/dist/api-handlers/session/refresh-viability.js +39 -0
  67. package/dist/api-handlers/session/viability.d.ts +13 -0
  68. package/dist/api-handlers/session/viability.js +114 -0
  69. package/dist/api-handlers/test/force-expire.d.ts +23 -0
  70. package/dist/api-handlers/test/force-expire.js +59 -0
  71. package/dist/auth/auth-decision.d.ts +39 -0
  72. package/dist/auth/auth-decision.js +182 -0
  73. package/dist/auth/better-auth.d.ts +79 -0
  74. package/dist/auth/better-auth.js +119 -0
  75. package/dist/auth/route-config.d.ts +66 -0
  76. package/dist/auth/route-config.js +190 -0
  77. package/dist/auth/types/auth-types.d.ts +417 -0
  78. package/dist/auth/types/auth-types.js +53 -0
  79. package/dist/auth/types/index.d.ts +6 -0
  80. package/dist/auth/types/index.js +22 -0
  81. package/dist/auth/unauthenticated-routes.d.ts +1 -0
  82. package/dist/auth/unauthenticated-routes.js +19 -0
  83. package/dist/auth/utils/idp-client.d.ts +94 -0
  84. package/dist/auth/utils/idp-client.js +384 -0
  85. package/dist/auth/utils/index.d.ts +5 -0
  86. package/dist/auth/utils/index.js +21 -0
  87. package/dist/auth/utils/token-utils.d.ts +83 -0
  88. package/dist/auth/utils/token-utils.js +218 -0
  89. package/dist/client/AuthContext.d.ts +19 -0
  90. package/dist/client/AuthContext.js +115 -0
  91. package/dist/client/better-auth-client.d.ts +1020 -0
  92. package/dist/client/better-auth-client.js +68 -0
  93. package/dist/client/fetch-with-auth.d.ts +11 -0
  94. package/dist/client/fetch-with-auth.js +44 -0
  95. package/dist/client/fetchWithSession.d.ts +3 -0
  96. package/dist/client/fetchWithSession.js +24 -0
  97. package/dist/client/index.d.ts +9 -0
  98. package/dist/client/index.js +20 -0
  99. package/dist/client/useAnonSession.d.ts +36 -0
  100. package/dist/client/useAnonSession.js +99 -0
  101. package/dist/components/SessionSync.d.ts +13 -0
  102. package/dist/components/SessionSync.js +121 -0
  103. package/dist/components/SignalRHealthCheck.d.ts +10 -0
  104. package/dist/components/SignalRHealthCheck.js +97 -0
  105. package/dist/components/account/MobileNavDrawer.d.ts +32 -0
  106. package/dist/components/account/MobileNavDrawer.js +81 -0
  107. package/dist/components/account/UserAvatarMenu.d.ts +20 -0
  108. package/dist/components/account/UserAvatarMenu.js +91 -0
  109. package/dist/components/account/index.d.ts +9 -0
  110. package/dist/components/account/index.js +13 -0
  111. package/dist/components/admin/AlertSettingsTab.d.ts +48 -0
  112. package/dist/components/admin/AlertSettingsTab.js +351 -0
  113. package/dist/components/admin/AnalyticsTab.d.ts +22 -0
  114. package/dist/components/admin/AnalyticsTab.js +167 -0
  115. package/dist/components/admin/DataBrowserTab.d.ts +19 -0
  116. package/dist/components/admin/DataBrowserTab.js +252 -0
  117. package/dist/components/admin/LoggingSettingsTab.d.ts +73 -0
  118. package/dist/components/admin/LoggingSettingsTab.js +339 -0
  119. package/dist/components/admin/SessionsTab.d.ts +37 -0
  120. package/dist/components/admin/SessionsTab.js +165 -0
  121. package/dist/components/admin/StatsTab.d.ts +53 -0
  122. package/dist/components/admin/StatsTab.js +161 -0
  123. package/dist/components/admin/VibeAdminContext.d.ts +32 -0
  124. package/dist/components/admin/VibeAdminContext.js +38 -0
  125. package/dist/components/admin/VibeAdminLayout.d.ts +11 -0
  126. package/dist/components/admin/VibeAdminLayout.js +71 -0
  127. package/dist/components/admin/index.d.ts +29 -0
  128. package/dist/components/admin/index.js +44 -0
  129. package/dist/components/auth/FederatedAuthSection.d.ts +8 -0
  130. package/dist/components/auth/FederatedAuthSection.js +45 -0
  131. package/dist/components/auth/ModeAwareLoginPage.d.ts +10 -0
  132. package/dist/components/auth/ModeAwareLoginPage.js +42 -0
  133. package/dist/components/auth/ModeAwareSignupPage.d.ts +9 -0
  134. package/dist/components/auth/ModeAwareSignupPage.js +78 -0
  135. package/dist/components/auth/TraditionalAuthSection.d.ts +14 -0
  136. package/dist/components/auth/TraditionalAuthSection.js +20 -0
  137. package/dist/components/recovery/CompleteStep.d.ts +5 -0
  138. package/dist/components/recovery/CompleteStep.js +8 -0
  139. package/dist/components/recovery/InitiateRecoveryStep.d.ts +8 -0
  140. package/dist/components/recovery/InitiateRecoveryStep.js +20 -0
  141. package/dist/components/recovery/SelectMethodStep.d.ts +8 -0
  142. package/dist/components/recovery/SelectMethodStep.js +8 -0
  143. package/dist/components/recovery/SetPasswordStep.d.ts +6 -0
  144. package/dist/components/recovery/SetPasswordStep.js +20 -0
  145. package/dist/components/recovery/VerifyCodeStep.d.ts +10 -0
  146. package/dist/components/recovery/VerifyCodeStep.js +24 -0
  147. package/dist/components/reserved/ReservedRecoveryWarning.d.ts +38 -0
  148. package/dist/components/reserved/ReservedRecoveryWarning.js +92 -0
  149. package/dist/components/reserved/ReservedStatusBox.d.ts +30 -0
  150. package/dist/components/reserved/ReservedStatusBox.js +71 -0
  151. package/dist/components/ui/BetaBadge.d.ts +29 -0
  152. package/dist/components/ui/BetaBadge.js +38 -0
  153. package/dist/components/ui/Footer.d.ts +37 -0
  154. package/dist/components/ui/Footer.js +41 -0
  155. package/dist/config/env.d.ts +66 -0
  156. package/dist/config/env.js +57 -0
  157. package/dist/config/logger.d.ts +57 -0
  158. package/dist/config/logger.js +73 -0
  159. package/dist/config/logging-config.d.ts +30 -0
  160. package/dist/config/logging-config.js +122 -0
  161. package/dist/config/unauthenticated-routes.d.ts +17 -0
  162. package/dist/config/unauthenticated-routes.js +24 -0
  163. package/dist/config/vibe-log-transport.d.ts +81 -0
  164. package/dist/config/vibe-log-transport.js +212 -0
  165. package/dist/edge/internal-api-url.d.ts +53 -0
  166. package/dist/edge/internal-api-url.js +63 -0
  167. package/dist/edge/middleware.d.ts +14 -0
  168. package/dist/edge/middleware.js +32 -0
  169. package/dist/hooks/useAuth.d.ts +23 -0
  170. package/dist/hooks/useAuth.js +83 -0
  171. package/dist/hooks/useAuthSettings.d.ts +59 -0
  172. package/dist/hooks/useAuthSettings.js +93 -0
  173. package/dist/hooks/useAvailableProviders.d.ts +43 -0
  174. package/dist/hooks/useAvailableProviders.js +112 -0
  175. package/dist/hooks/usePasswordValidation.d.ts +27 -0
  176. package/dist/hooks/usePasswordValidation.js +102 -0
  177. package/dist/hooks/useProfile.d.ts +15 -0
  178. package/dist/hooks/useProfile.js +59 -0
  179. package/dist/hooks/usePublicAuthSettings.d.ts +56 -0
  180. package/dist/hooks/usePublicAuthSettings.js +131 -0
  181. package/dist/hooks/useSessionExpiration.d.ts +56 -0
  182. package/dist/hooks/useSessionExpiration.js +72 -0
  183. package/dist/hooks/useViabilitySession.d.ts +75 -0
  184. package/dist/hooks/useViabilitySession.js +269 -0
  185. package/dist/index.d.ts +12 -0
  186. package/dist/index.js +53 -0
  187. package/dist/lib/anon-session.d.ts +74 -0
  188. package/dist/lib/anon-session.js +169 -0
  189. package/dist/lib/api-handler.d.ts +123 -0
  190. package/dist/lib/api-handler.js +478 -0
  191. package/dist/lib/app-slug.d.ts +95 -0
  192. package/dist/lib/app-slug.js +172 -0
  193. package/dist/lib/demo-mode.d.ts +6 -0
  194. package/dist/lib/demo-mode.js +16 -0
  195. package/dist/lib/geolocation.d.ts +64 -0
  196. package/dist/lib/geolocation.js +235 -0
  197. package/dist/lib/idp-client-config.d.ts +75 -0
  198. package/dist/lib/idp-client-config.js +425 -0
  199. package/dist/lib/idp-fetch.d.ts +14 -0
  200. package/dist/lib/idp-fetch.js +91 -0
  201. package/dist/lib/internal-api.d.ts +87 -0
  202. package/dist/lib/internal-api.js +122 -0
  203. package/dist/lib/jwt-decode-client.d.ts +10 -0
  204. package/dist/lib/jwt-decode-client.js +46 -0
  205. package/dist/lib/jwt-decode.d.ts +48 -0
  206. package/dist/lib/jwt-decode.js +57 -0
  207. package/dist/lib/rate-limit-service.d.ts +23 -0
  208. package/dist/lib/rate-limit-service.js +6 -0
  209. package/dist/lib/redis.d.ts +5 -0
  210. package/dist/lib/redis.js +28 -0
  211. package/dist/lib/refresh-token-validator.d.ts +13 -0
  212. package/dist/lib/refresh-token-validator.js +117 -0
  213. package/dist/lib/roles.d.ts +145 -0
  214. package/dist/lib/roles.js +168 -0
  215. package/dist/lib/secret-validation.d.ts +4 -0
  216. package/dist/lib/secret-validation.js +14 -0
  217. package/dist/lib/session-store.d.ts +170 -0
  218. package/dist/lib/session-store.js +545 -0
  219. package/dist/lib/session.d.ts +21 -0
  220. package/dist/lib/session.js +26 -0
  221. package/dist/lib/site-logger.d.ts +214 -0
  222. package/dist/lib/site-logger.js +210 -0
  223. package/dist/lib/standardized-client-api.d.ts +161 -0
  224. package/dist/lib/standardized-client-api.js +791 -0
  225. package/dist/lib/startup-init.d.ts +40 -0
  226. package/dist/lib/startup-init.js +257 -0
  227. package/dist/lib/test-aware-get-token.d.ts +2 -0
  228. package/dist/lib/test-aware-get-token.js +86 -0
  229. package/dist/lib/token-expiry.d.ts +14 -0
  230. package/dist/lib/token-expiry.js +39 -0
  231. package/dist/lib/token-lifecycle.d.ts +78 -0
  232. package/dist/lib/token-lifecycle.js +360 -0
  233. package/dist/lib/types/api-responses.d.ts +128 -0
  234. package/dist/lib/types/api-responses.js +171 -0
  235. package/dist/lib/user-agent-parser.d.ts +50 -0
  236. package/dist/lib/user-agent-parser.js +220 -0
  237. package/dist/logging/api/admin-analytics.d.ts +3 -0
  238. package/dist/logging/api/admin-analytics.js +45 -0
  239. package/dist/logging/api/audit-log.d.ts +3 -0
  240. package/dist/logging/api/audit-log.js +52 -0
  241. package/dist/logging/components/AdminAnalyticsLayout.d.ts +10 -0
  242. package/dist/logging/components/AdminAnalyticsLayout.js +11 -0
  243. package/dist/logging/components/AuditLogViewer.d.ts +7 -0
  244. package/dist/logging/components/AuditLogViewer.js +51 -0
  245. package/dist/logging/components/ErrorMetricsCard.d.ts +7 -0
  246. package/dist/logging/components/ErrorMetricsCard.js +16 -0
  247. package/dist/logging/components/HealthMetricsCard.d.ts +7 -0
  248. package/dist/logging/components/HealthMetricsCard.js +19 -0
  249. package/dist/logging/hooks/useAdminAnalytics.d.ts +24 -0
  250. package/dist/logging/hooks/useAdminAnalytics.js +22 -0
  251. package/dist/logging/hooks/useAuditLog.d.ts +6 -0
  252. package/dist/logging/hooks/useAuditLog.js +25 -0
  253. package/dist/logging/hooks/useErrorMetrics.d.ts +6 -0
  254. package/dist/logging/hooks/useErrorMetrics.js +38 -0
  255. package/dist/logging/hooks/useHealthMetrics.d.ts +6 -0
  256. package/dist/logging/hooks/useHealthMetrics.js +41 -0
  257. package/dist/logging/index.d.ts +11 -0
  258. package/dist/logging/index.js +40 -0
  259. package/dist/logging/types/analytics.d.ts +68 -0
  260. package/dist/logging/types/analytics.js +3 -0
  261. package/dist/logging/types/audit.d.ts +29 -0
  262. package/dist/logging/types/audit.js +2 -0
  263. package/dist/logging/types/index.d.ts +2 -0
  264. package/dist/logging/types/index.js +19 -0
  265. package/dist/middleware/auth-decision.d.ts +33 -0
  266. package/dist/middleware/auth-decision.js +65 -0
  267. package/dist/middleware/create-middleware.d.ts +102 -0
  268. package/dist/middleware/create-middleware.js +469 -0
  269. package/dist/middleware/rbac-check.d.ts +51 -0
  270. package/dist/middleware/rbac-check.js +219 -0
  271. package/dist/middleware/twofa-presets.d.ts +134 -0
  272. package/dist/middleware/twofa-presets.js +175 -0
  273. package/dist/models/DecodedAccessToken.d.ts +17 -0
  274. package/dist/models/DecodedAccessToken.js +2 -0
  275. package/dist/models/SessionModel.d.ts +122 -0
  276. package/dist/models/SessionModel.js +136 -0
  277. package/dist/pages/admin-login/page.d.ts +31 -0
  278. package/dist/pages/admin-login/page.js +73 -0
  279. package/dist/pages/admin-page-permissions/PagePermissionsAdminPage.d.ts +18 -0
  280. package/dist/pages/admin-page-permissions/PagePermissionsAdminPage.js +276 -0
  281. package/dist/pages/admin-page-permissions/index.d.ts +6 -0
  282. package/dist/pages/admin-page-permissions/index.js +13 -0
  283. package/dist/pages/admin-roles/RolesAdminPage.d.ts +16 -0
  284. package/dist/pages/admin-roles/RolesAdminPage.js +261 -0
  285. package/dist/pages/admin-roles/index.d.ts +8 -0
  286. package/dist/pages/admin-roles/index.js +15 -0
  287. package/dist/pages/admin-roles/modals.d.ts +72 -0
  288. package/dist/pages/admin-roles/modals.js +154 -0
  289. package/dist/pages/client-admin/ClientSiteAdminPage.d.ts +79 -0
  290. package/dist/pages/client-admin/ClientSiteAdminPage.js +179 -0
  291. package/dist/pages/client-admin/index.d.ts +32 -0
  292. package/dist/pages/client-admin/index.js +37 -0
  293. package/dist/pages/coming-soon/page.d.ts +8 -0
  294. package/dist/pages/coming-soon/page.js +28 -0
  295. package/dist/pages/login/page.d.ts +22 -0
  296. package/dist/pages/login/page.js +230 -0
  297. package/dist/pages/profile/EnhancedProfilePage.d.ts +13 -0
  298. package/dist/pages/profile/EnhancedProfilePage.js +150 -0
  299. package/dist/pages/profile/index.d.ts +8 -0
  300. package/dist/pages/profile/index.js +16 -0
  301. package/dist/pages/profile/page.d.ts +19 -0
  302. package/dist/pages/profile/page.js +47 -0
  303. package/dist/pages/recovery/page.d.ts +1 -0
  304. package/dist/pages/recovery/page.js +142 -0
  305. package/dist/pages/roles/MyRolesPage.d.ts +24 -0
  306. package/dist/pages/roles/MyRolesPage.js +71 -0
  307. package/dist/pages/roles/components.d.ts +63 -0
  308. package/dist/pages/roles/components.js +108 -0
  309. package/dist/pages/roles/index.d.ts +8 -0
  310. package/dist/pages/roles/index.js +19 -0
  311. package/dist/pages/security/EnhancedSecurityPage.d.ts +14 -0
  312. package/dist/pages/security/EnhancedSecurityPage.js +248 -0
  313. package/dist/pages/security/index.d.ts +8 -0
  314. package/dist/pages/security/index.js +16 -0
  315. package/dist/pages/security/page.d.ts +21 -0
  316. package/dist/pages/security/page.js +212 -0
  317. package/dist/pages/settings/EnhancedSettingsPage.d.ts +46 -0
  318. package/dist/pages/settings/EnhancedSettingsPage.js +231 -0
  319. package/dist/pages/settings/index.d.ts +8 -0
  320. package/dist/pages/settings/index.js +16 -0
  321. package/dist/pages/settings/page.d.ts +7 -0
  322. package/dist/pages/settings/page.js +26 -0
  323. package/dist/pages/showcase/ShowcasePage.d.ts +13 -0
  324. package/dist/pages/showcase/ShowcasePage.js +142 -0
  325. package/dist/pages/showcase/index.d.ts +12 -0
  326. package/dist/pages/showcase/index.js +17 -0
  327. package/dist/pages/test-env/EmergencyLogoutPage.d.ts +14 -0
  328. package/dist/pages/test-env/EmergencyLogoutPage.js +99 -0
  329. package/dist/pages/test-env/JwtInspectPage.d.ts +14 -0
  330. package/dist/pages/test-env/JwtInspectPage.js +116 -0
  331. package/dist/pages/test-env/RefreshTokenPage.d.ts +15 -0
  332. package/dist/pages/test-env/RefreshTokenPage.js +93 -0
  333. package/dist/pages/test-env/TestEnvPage.d.ts +13 -0
  334. package/dist/pages/test-env/TestEnvPage.js +51 -0
  335. package/dist/pages/test-env/index.d.ts +24 -0
  336. package/dist/pages/test-env/index.js +32 -0
  337. package/dist/pages/verify-code/page.d.ts +30 -0
  338. package/dist/pages/verify-code/page.js +412 -0
  339. package/dist/routes/account/index.d.ts +28 -0
  340. package/dist/routes/account/index.js +71 -0
  341. package/dist/routes/account/masked-info.d.ts +33 -0
  342. package/dist/routes/account/masked-info.js +39 -0
  343. package/dist/routes/account/send-code.d.ts +37 -0
  344. package/dist/routes/account/send-code.js +42 -0
  345. package/dist/routes/account/update-phone.d.ts +13 -0
  346. package/dist/routes/account/update-phone.js +17 -0
  347. package/dist/routes/account/verify-email.d.ts +38 -0
  348. package/dist/routes/account/verify-email.js +43 -0
  349. package/dist/routes/account/verify-sms.d.ts +38 -0
  350. package/dist/routes/account/verify-sms.js +43 -0
  351. package/dist/routes/auth/index.d.ts +19 -0
  352. package/dist/routes/auth/index.js +64 -0
  353. package/dist/routes/auth/logout.d.ts +31 -0
  354. package/dist/routes/auth/logout.js +98 -0
  355. package/dist/routes/auth/nextauth.d.ts +22 -0
  356. package/dist/routes/auth/nextauth.js +40 -0
  357. package/dist/routes/auth/refresh.d.ts +30 -0
  358. package/dist/routes/auth/refresh.js +51 -0
  359. package/dist/routes/auth/session.d.ts +43 -0
  360. package/dist/routes/auth/session.js +157 -0
  361. package/dist/routes/auth/settings.d.ts +25 -0
  362. package/dist/routes/auth/settings.js +55 -0
  363. package/dist/routes/auth/viability.d.ts +52 -0
  364. package/dist/routes/auth/viability.js +190 -0
  365. package/dist/routes/index.d.ts +12 -0
  366. package/dist/routes/index.js +54 -0
  367. package/dist/routes/session/index.d.ts +6 -0
  368. package/dist/routes/session/index.js +10 -0
  369. package/dist/routes/session/refresh-viability.d.ts +16 -0
  370. package/dist/routes/session/refresh-viability.js +20 -0
  371. package/dist/server/auth-guard.d.ts +46 -0
  372. package/dist/server/auth-guard.js +128 -0
  373. package/dist/server/auth.d.ts +50 -0
  374. package/dist/server/auth.js +62 -0
  375. package/dist/server/decode-session.d.ts +30 -0
  376. package/dist/server/decode-session.js +78 -0
  377. package/dist/server/slim-middleware.d.ts +23 -0
  378. package/dist/server/slim-middleware.js +89 -0
  379. package/dist/server/with-auth.d.ts +33 -0
  380. package/dist/server/with-auth.js +59 -0
  381. package/dist/services/signalrActivityService.d.ts +44 -0
  382. package/dist/services/signalrActivityService.js +257 -0
  383. package/dist/stores/authStore.d.ts +154 -0
  384. package/dist/stores/authStore.js +1527 -0
  385. package/dist/theme/ThemeProvider.d.ts +14 -0
  386. package/dist/theme/ThemeProvider.js +28 -0
  387. package/dist/theme/default.d.ts +8 -0
  388. package/dist/theme/default.js +33 -0
  389. package/dist/theme/index.d.ts +15 -0
  390. package/dist/theme/index.js +25 -0
  391. package/dist/theme/types.d.ts +56 -0
  392. package/dist/theme/types.js +8 -0
  393. package/dist/theme/useTheme.d.ts +60 -0
  394. package/dist/theme/useTheme.js +63 -0
  395. package/dist/theme/utils.d.ts +13 -0
  396. package/dist/theme/utils.js +39 -0
  397. package/dist/types/api.d.ts +134 -0
  398. package/dist/types/api.js +44 -0
  399. package/dist/types/auth.d.ts +19 -0
  400. package/dist/types/auth.js +2 -0
  401. package/dist/types/logging.d.ts +42 -0
  402. package/dist/types/logging.js +2 -0
  403. package/dist/types/recovery.d.ts +48 -0
  404. package/dist/types/recovery.js +2 -0
  405. package/dist/types/security.d.ts +1 -0
  406. package/dist/types/security.js +2 -0
  407. package/dist/utils/api.d.ts +85 -0
  408. package/dist/utils/api.js +287 -0
  409. package/dist/utils/circuitBreaker.d.ts +43 -0
  410. package/dist/utils/circuitBreaker.js +91 -0
  411. package/dist/utils/error-message.d.ts +1 -0
  412. package/dist/utils/error-message.js +103 -0
  413. package/dist/utils/layout/reservedSpace.d.ts +59 -0
  414. package/dist/utils/layout/reservedSpace.js +102 -0
  415. package/dist/utils/logout.d.ts +14 -0
  416. package/dist/utils/logout.js +32 -0
  417. package/dist/vibe/client.d.ts +261 -0
  418. package/dist/vibe/client.js +445 -0
  419. package/dist/vibe/enterprise-auth.d.ts +106 -0
  420. package/dist/vibe/enterprise-auth.js +173 -0
  421. package/dist/vibe/errors.d.ts +83 -0
  422. package/dist/vibe/errors.js +146 -0
  423. package/dist/vibe/generic.d.ts +234 -0
  424. package/dist/vibe/generic.js +369 -0
  425. package/dist/vibe/hooks/index.d.ts +169 -0
  426. package/dist/vibe/hooks/index.js +252 -0
  427. package/dist/vibe/index.d.ts +25 -0
  428. package/dist/vibe/index.js +72 -0
  429. package/dist/vibe/sessions.d.ts +161 -0
  430. package/dist/vibe/sessions.js +391 -0
  431. package/dist/vibe/types.d.ts +353 -0
  432. package/dist/vibe/types.js +315 -0
  433. package/package.json +1 -1
  434. package/src/auth/better-auth.ts +2 -2
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /**
3
+ * Ready-to-Use Auth Route Handler (Better Auth)
4
+ *
5
+ * Provides a pre-configured Better Auth handler that uses dynamic OAuth providers
6
+ * loaded from IDP at startup.
7
+ *
8
+ * Replaces the former NextAuth handler. The file name is kept as nextauth.ts
9
+ * to avoid breaking re-exports in routes/auth/index.ts.
10
+ *
11
+ * @version 4.0.0 - Better Auth migration
12
+ * @since better-auth-4.0
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.GET = GET;
16
+ exports.POST = POST;
17
+ const better_auth_1 = require("../../auth/better-auth");
18
+ const server_1 = require("next/server");
19
+ /**
20
+ * GET handler for auth routes
21
+ * Delegates to Better Auth instance.
22
+ */
23
+ async function GET(request) {
24
+ const handler = await (0, better_auth_1.getBetterAuthHandler)();
25
+ if (!handler) {
26
+ return server_1.NextResponse.json({ error: 'Auth handler not available' }, { status: 503 });
27
+ }
28
+ return handler.GET(request);
29
+ }
30
+ /**
31
+ * POST handler for auth routes
32
+ * Delegates to Better Auth instance.
33
+ */
34
+ async function POST(request) {
35
+ const handler = await (0, better_auth_1.getBetterAuthHandler)();
36
+ if (!handler) {
37
+ return server_1.NextResponse.json({ error: 'Auth handler not available' }, { status: 503 });
38
+ }
39
+ return handler.POST(request);
40
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Ready-to-Use Refresh Token Route
3
+ *
4
+ * Provides a pre-configured refresh handler that can be imported directly
5
+ * into your app's API routes with zero configuration.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // app/api/auth/refresh/route.ts
10
+ * export { POST } from '@payez/next-mvp/routes/auth/refresh';
11
+ * ```
12
+ *
13
+ * @version 2.0.0
14
+ * @since auth-ready-v2
15
+ */
16
+ import { NextRequest } from 'next/server';
17
+ export declare function POST(req: NextRequest): Promise<import("next/server").NextResponse<{
18
+ error: string;
19
+ code: string;
20
+ }> | import("next/server").NextResponse<{
21
+ error: any;
22
+ code: any;
23
+ discardToken: boolean;
24
+ retryable: boolean;
25
+ resolution: any;
26
+ }> | import("next/server").NextResponse<{
27
+ refreshed: boolean;
28
+ accessTokenExpires: number;
29
+ hasRefreshToken: boolean;
30
+ }>>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /**
3
+ * Ready-to-Use Refresh Token Route
4
+ *
5
+ * Provides a pre-configured refresh handler that can be imported directly
6
+ * into your app's API routes with zero configuration.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // app/api/auth/refresh/route.ts
11
+ * export { POST } from '@payez/next-mvp/routes/auth/refresh';
12
+ * ```
13
+ *
14
+ * @version 2.0.0
15
+ * @since auth-ready-v2
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.POST = POST;
19
+ const refresh_1 = require("../../api-handlers/auth/refresh");
20
+ const idp_client_config_1 = require("../../lib/idp-client-config");
21
+ // Configuration is read at runtime from IDP config (cached)
22
+ async function getConfig() {
23
+ const idpConfig = await (0, idp_client_config_1.getIDPClientConfig)();
24
+ const idpBaseUrl = process.env.IDP_URL;
25
+ if (!idpBaseUrl) {
26
+ throw new Error('[IDP_URL] FATAL: IDP_URL environment variable is REQUIRED.');
27
+ }
28
+ return {
29
+ idpBaseUrl,
30
+ clientId: process.env.CLIENT_ID || process.env.NEXT_PUBLIC_IDP_CLIENT_ID || '',
31
+ nextAuthSecret: idpConfig.nextAuthSecret || '',
32
+ refreshEndpoint: process.env.REFRESH_ENDPOINT || '/api/ExternalAuth/refresh',
33
+ };
34
+ }
35
+ /**
36
+ * Pre-configured POST handler for token refresh
37
+ *
38
+ * Environment variables used:
39
+ * - IDP_URL (REQUIRED)
40
+ * - CLIENT_ID or NEXT_PUBLIC_IDP_CLIENT_ID (required)
41
+ * - NEXTAUTH_SECRET (required)
42
+ * - REFRESH_ENDPOINT (default: /api/ExternalAuth/refresh)
43
+ */
44
+ let _handler = null;
45
+ async function POST(req) {
46
+ if (!_handler) {
47
+ const config = await getConfig();
48
+ _handler = (0, refresh_1.createRefreshHandler)(config);
49
+ }
50
+ return _handler(req);
51
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Ready-to-Use Session Management Route
3
+ *
4
+ * Provides pre-configured session handlers for checking and updating session state.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // app/api/auth/session/route.ts
9
+ * export { GET, POST } from '@payez/next-mvp/routes/auth/session';
10
+ * ```
11
+ *
12
+ * @version 2.0.0
13
+ * @since auth-ready-v2
14
+ */
15
+ import { NextRequest, NextResponse } from 'next/server';
16
+ /**
17
+ * GET /api/auth/session - Check current session status
18
+ *
19
+ * Returns the current session information including:
20
+ * - User details
21
+ * - Token expiry status
22
+ * - Session validity
23
+ */
24
+ export declare function GET(req: NextRequest): Promise<NextResponse<{}>>;
25
+ /**
26
+ * POST /api/auth/session - Update session data
27
+ *
28
+ * Allows updating session metadata (not tokens).
29
+ * Token refresh should use the /api/auth/refresh endpoint.
30
+ *
31
+ * Body:
32
+ * - metadata: object - Custom metadata to store in session
33
+ */
34
+ export declare function POST(req: NextRequest): Promise<NextResponse<{
35
+ error: string;
36
+ code: string;
37
+ }> | NextResponse<{
38
+ success: boolean;
39
+ message: string;
40
+ }> | NextResponse<{
41
+ error: string;
42
+ details: string;
43
+ }>>;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ /**
3
+ * Ready-to-Use Session Management Route
4
+ *
5
+ * Provides pre-configured session handlers for checking and updating session state.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // app/api/auth/session/route.ts
10
+ * export { GET, POST } from '@payez/next-mvp/routes/auth/session';
11
+ * ```
12
+ *
13
+ * @version 2.0.0
14
+ * @since auth-ready-v2
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.GET = GET;
18
+ exports.POST = POST;
19
+ const server_1 = require("next/server");
20
+ const auth_1 = require("../../server/auth");
21
+ const session_store_1 = require("../../lib/session-store");
22
+ /**
23
+ * GET /api/auth/session - Check current session status
24
+ *
25
+ * Returns the current session information including:
26
+ * - User details
27
+ * - Token expiry status
28
+ * - Session validity
29
+ */
30
+ async function GET(req) {
31
+ try {
32
+ const authSession = await (0, auth_1.getSession)(req);
33
+ if (!authSession) {
34
+ console.warn('[SESSION_ROUTE] Better Auth session not found');
35
+ // MUST return empty {} — useSession() treats any non-empty
36
+ // response object as "authenticated", causing redirect loops on login page.
37
+ return server_1.NextResponse.json({});
38
+ }
39
+ const redisSessionId = authSession.session?.token;
40
+ console.log('[SESSION_ROUTE] Session found:', {
41
+ userId: authSession.user?.id,
42
+ email: authSession.user?.email,
43
+ name: authSession.user?.name,
44
+ redisSessionId: redisSessionId ? redisSessionId.substring(0, 8) + '...' : 'MISSING',
45
+ });
46
+ // Fetch full session data from Redis
47
+ const session = redisSessionId ? await (0, session_store_1.getSession)(redisSessionId) : null;
48
+ console.log('[SESSION_ROUTE] Redis session:', {
49
+ found: !!session,
50
+ userId: session?.userId,
51
+ roles: session?.roles,
52
+ hasAccessToken: !!session?.idpAccessToken,
53
+ });
54
+ // Return session format with Redis data
55
+ // useSession() expects: { user: {...}, expires: "..." }
56
+ // We enrich with all session data from Redis
57
+ return server_1.NextResponse.json({
58
+ user: {
59
+ id: session?.userId || authSession.user?.id,
60
+ email: session?.email || authSession.user?.email,
61
+ name: session?.name || authSession.user?.name,
62
+ image: authSession.user?.image || null,
63
+ // Redis session data
64
+ roles: session?.roles || [],
65
+ twoFactorSessionVerified: session?.mfaVerified || false,
66
+ requiresTwoFactor: !session?.mfaVerified,
67
+ authenticationMethods: session?.authenticationMethods,
68
+ authenticationLevel: session?.authenticationLevel,
69
+ mfaCompletedAt: session?.mfaCompletedAt,
70
+ mfaExpiresAt: session?.mfaExpiresAt,
71
+ mfaValidityHours: session?.mfaValidityHours,
72
+ oauthProvider: session?.oauthProvider,
73
+ idpClientId: session?.idpClientId,
74
+ merchantId: session?.merchantId,
75
+ },
76
+ // Session tokens
77
+ sessionToken: redisSessionId,
78
+ accessToken: session?.idpAccessToken,
79
+ refreshToken: session?.idpRefreshToken,
80
+ accessTokenExpires: session?.idpAccessTokenExpires,
81
+ expires: authSession.session?.expiresAt
82
+ ? new Date(authSession.session.expiresAt).toISOString()
83
+ : new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(),
84
+ });
85
+ }
86
+ catch (error) {
87
+ console.error('[SESSION_ROUTE] Error checking session:', error);
88
+ return server_1.NextResponse.json({
89
+ error: 'Failed to check session',
90
+ details: error instanceof Error ? error.message : 'Unknown error'
91
+ }, { status: 500 });
92
+ }
93
+ }
94
+ /**
95
+ * POST /api/auth/session - Update session data
96
+ *
97
+ * Allows updating session metadata (not tokens).
98
+ * Token refresh should use the /api/auth/refresh endpoint.
99
+ *
100
+ * Body:
101
+ * - metadata: object - Custom metadata to store in session
102
+ */
103
+ async function POST(req) {
104
+ try {
105
+ const authSession = await (0, auth_1.getSession)(req);
106
+ if (!authSession) {
107
+ return server_1.NextResponse.json({
108
+ error: 'No session found',
109
+ code: 'UNAUTHORIZED'
110
+ }, { status: 401 });
111
+ }
112
+ const sessionToken = authSession.session?.token;
113
+ if (!sessionToken) {
114
+ return server_1.NextResponse.json({
115
+ error: 'Invalid session',
116
+ code: 'INVALID_SESSION'
117
+ }, { status: 400 });
118
+ }
119
+ const body = await req.json();
120
+ const { metadata, access_token, refresh_token, twoFactorComplete, twoFactorMethod } = body;
121
+ // Get current session from Redis
122
+ const session = await (0, session_store_1.getSession)(sessionToken);
123
+ if (!session) {
124
+ return server_1.NextResponse.json({
125
+ error: 'Session not found',
126
+ code: 'SESSION_NOT_FOUND'
127
+ }, { status: 404 });
128
+ }
129
+ // Update session with new data
130
+ const updatedSession = {
131
+ ...session,
132
+ ...(access_token ? { accessToken: access_token } : {}),
133
+ ...(refresh_token ? { refreshToken: refresh_token } : {}),
134
+ ...(typeof twoFactorComplete === 'boolean' ? { twoFactorComplete } : {}),
135
+ ...(twoFactorMethod ? { twoFactorMethod } : {}),
136
+ ...(metadata ? {
137
+ metadata: {
138
+ ...(session.metadata || {}),
139
+ ...metadata,
140
+ updatedAt: new Date().toISOString()
141
+ }
142
+ } : {})
143
+ };
144
+ await (0, session_store_1.updateSession)(sessionToken, updatedSession);
145
+ return server_1.NextResponse.json({
146
+ success: true,
147
+ message: 'Session updated successfully'
148
+ });
149
+ }
150
+ catch (error) {
151
+ console.error('[SESSION_ROUTE] Error updating session:', error);
152
+ return server_1.NextResponse.json({
153
+ error: 'Failed to update session',
154
+ details: error instanceof Error ? error.message : 'Unknown error'
155
+ }, { status: 500 });
156
+ }
157
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Public Auth Settings Route
3
+ *
4
+ * Returns client auth settings for pre-login pages (signup, login).
5
+ * Does NOT require authentication - these are public client settings.
6
+ */
7
+ import { NextResponse } from 'next/server';
8
+ export interface PublicAuthSettings {
9
+ enabledProviders: string[];
10
+ allowPublicRegistration: boolean;
11
+ allowSocialLogin: boolean;
12
+ enablePasswordReset: boolean;
13
+ require2FA: boolean;
14
+ allowed2FAMethods: string[];
15
+ }
16
+ /**
17
+ * GET /api/auth/settings
18
+ *
19
+ * Returns public auth settings for the current client.
20
+ * Used by login/signup pages to determine what options to show.
21
+ */
22
+ export declare function GET(): Promise<NextResponse<{
23
+ success: boolean;
24
+ data: PublicAuthSettings;
25
+ }>>;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /**
3
+ * Public Auth Settings Route
4
+ *
5
+ * Returns client auth settings for pre-login pages (signup, login).
6
+ * Does NOT require authentication - these are public client settings.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.GET = GET;
10
+ const server_1 = require("next/server");
11
+ const idp_client_config_1 = require("../../lib/idp-client-config");
12
+ /**
13
+ * GET /api/auth/settings
14
+ *
15
+ * Returns public auth settings for the current client.
16
+ * Used by login/signup pages to determine what options to show.
17
+ */
18
+ async function GET() {
19
+ try {
20
+ const config = await (0, idp_client_config_1.getIDPClientConfig)();
21
+ const settings = {
22
+ // Get enabled OAuth provider names
23
+ enabledProviders: config.oauthProviders
24
+ ?.filter(p => p.enabled)
25
+ .map(p => p.provider) ?? [],
26
+ // Registration - default to true if not specified
27
+ allowPublicRegistration: true, // Could come from config.authSettings in future
28
+ allowSocialLogin: config.oauthProviders?.some(p => p.enabled) ?? false,
29
+ // Password reset
30
+ enablePasswordReset: true, // Could come from config.authSettings in future
31
+ // 2FA
32
+ require2FA: config.authSettings?.require2FA ?? true,
33
+ allowed2FAMethods: config.authSettings?.allowed2FAMethods ?? ['email', 'sms'],
34
+ };
35
+ return server_1.NextResponse.json({
36
+ success: true,
37
+ data: settings,
38
+ });
39
+ }
40
+ catch (error) {
41
+ console.error('[AUTH_SETTINGS] Failed to get settings:', error);
42
+ // Return safe defaults on error
43
+ return server_1.NextResponse.json({
44
+ success: true,
45
+ data: {
46
+ enabledProviders: [],
47
+ allowPublicRegistration: true,
48
+ allowSocialLogin: false,
49
+ enablePasswordReset: true,
50
+ require2FA: true,
51
+ allowed2FAMethods: ['email', 'sms'],
52
+ },
53
+ });
54
+ }
55
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Ready-to-Use Session Viability Route
3
+ *
4
+ * Checks if the current session is viable (valid and not expired).
5
+ * Used by client-side code to determine if a refresh is needed.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // app/api/session/viability/route.ts
10
+ * export { GET } from '@payez/next-mvp/routes/auth/viability';
11
+ * ```
12
+ *
13
+ * @version 2.0.0
14
+ * @since auth-ready-v2
15
+ */
16
+ import { NextRequest, NextResponse } from 'next/server';
17
+ /**
18
+ * GET /api/session/viability - Check if session is viable
19
+ *
20
+ * Returns:
21
+ * - viable: boolean - Whether the session can be used
22
+ * - needsRefresh: boolean - Whether a refresh is recommended
23
+ * - expiresIn: number - Seconds until token expires
24
+ */
25
+ export declare function GET(req: NextRequest): Promise<NextResponse<{
26
+ viable: boolean;
27
+ needsRefresh: boolean;
28
+ authenticated: boolean;
29
+ reason: string;
30
+ }> | NextResponse<{
31
+ viable: boolean;
32
+ needsRefresh: boolean;
33
+ expiresIn: number;
34
+ hasRefreshToken: boolean;
35
+ authenticated: boolean;
36
+ sessionToken: any;
37
+ tenantRequiresTwoFactor: boolean;
38
+ userHasCompletedTenantTwoFactorRequirements: any;
39
+ userStillNeedsTwoFactor: boolean;
40
+ requires2FA: boolean;
41
+ twoFactorComplete: any;
42
+ accessTokenExpired: boolean;
43
+ expiresAt: string;
44
+ roles: string[];
45
+ clientId: string;
46
+ }> | NextResponse<{
47
+ viable: boolean;
48
+ needsRefresh: boolean;
49
+ authenticated: boolean;
50
+ error: string;
51
+ details: string;
52
+ }>>;
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ /**
3
+ * Ready-to-Use Session Viability Route
4
+ *
5
+ * Checks if the current session is viable (valid and not expired).
6
+ * Used by client-side code to determine if a refresh is needed.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // app/api/session/viability/route.ts
11
+ * export { GET } from '@payez/next-mvp/routes/auth/viability';
12
+ * ```
13
+ *
14
+ * @version 2.0.0
15
+ * @since auth-ready-v2
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.GET = GET;
19
+ const server_1 = require("next/server");
20
+ const auth_1 = require("../../server/auth");
21
+ const session_store_1 = require("../../lib/session-store");
22
+ const idp_client_config_1 = require("../../lib/idp-client-config");
23
+ /**
24
+ * Get tenant-wide 2FA requirement from cached client config (from broker handshake)
25
+ */
26
+ async function getTenantRequiresTwoFactor() {
27
+ try {
28
+ const config = await (0, idp_client_config_1.getIDPClientConfig)();
29
+ return config.authSettings?.require2FA ?? true; // Default to true for security
30
+ }
31
+ catch {
32
+ console.warn('[VIABILITY] Could not get client config, defaulting tenantRequiresTwoFactor to true');
33
+ return true;
34
+ }
35
+ }
36
+ /**
37
+ * GET /api/session/viability - Check if session is viable
38
+ *
39
+ * Returns:
40
+ * - viable: boolean - Whether the session can be used
41
+ * - needsRefresh: boolean - Whether a refresh is recommended
42
+ * - expiresIn: number - Seconds until token expires
43
+ */
44
+ async function GET(req) {
45
+ try {
46
+ const baSession = await (0, auth_1.getSession)(req);
47
+ if (!baSession) {
48
+ return server_1.NextResponse.json({
49
+ viable: false,
50
+ needsRefresh: false,
51
+ authenticated: false,
52
+ reason: 'No session found'
53
+ });
54
+ }
55
+ const token = baSession;
56
+ const sessionToken = baSession.session?.token;
57
+ const session = sessionToken ? await (0, session_store_1.getSession)(sessionToken) : null;
58
+ // CRITICAL: Detect stale cookie state (JWT exists but Redis session missing)
59
+ if (sessionToken && !session) {
60
+ console.warn('[VIABILITY] Stale cookie detected - session not in Redis');
61
+ return server_1.NextResponse.json({
62
+ viable: false,
63
+ needsRefresh: false,
64
+ authenticated: false,
65
+ sessionToken, // Return sessionToken so middleware can detect and clear stale cookie
66
+ reason: 'Stale session - cookie exists but session not found in Redis'
67
+ });
68
+ }
69
+ // Check access token expiry
70
+ const now = Math.floor(Date.now() / 1000);
71
+ const accessTokenExpires = token.accessTokenExpires || token.exp;
72
+ if (!accessTokenExpires) {
73
+ // No expiry info, assume viable but recommend refresh
74
+ const tenantRequiresTwoFactor = await getTenantRequiresTwoFactor();
75
+ // CRITICAL: Check if MFA has expired (2FA TTL enforcement)
76
+ const mfaExpiresAt = session?.mfaExpiresAt || 0;
77
+ const mfaExpired = mfaExpiresAt > 0 && mfaExpiresAt < Date.now();
78
+ // Check mfaVerified (normalized name) with fallback to twoFactorComplete for compatibility
79
+ const mfaVerifiedInSession = session?.mfaVerified ?? session?.twoFactorComplete ?? false;
80
+ // User has completed 2FA requirements if: they verified AND it hasn't expired
81
+ const userHasCompletedTenantTwoFactorRequirements = mfaVerifiedInSession && !mfaExpired;
82
+ // userStillNeedsTwoFactor = inverse of completed (matches session callback logic)
83
+ const userStillNeedsTwoFactor = !userHasCompletedTenantTwoFactorRequirements;
84
+ return server_1.NextResponse.json({
85
+ viable: true,
86
+ needsRefresh: true,
87
+ authenticated: true,
88
+ sessionToken,
89
+ // Clear names for middleware decision-making
90
+ tenantRequiresTwoFactor,
91
+ userHasCompletedTenantTwoFactorRequirements,
92
+ userStillNeedsTwoFactor,
93
+ // Legacy field names for backwards compatibility
94
+ requires2FA: tenantRequiresTwoFactor,
95
+ twoFactorComplete: userHasCompletedTenantTwoFactorRequirements,
96
+ accessTokenExpired: false,
97
+ reason: 'No expiry information'
98
+ });
99
+ }
100
+ // Convert to seconds if needed
101
+ const expiryTime = accessTokenExpires > 1000000000000
102
+ ? Math.floor(accessTokenExpires / 1000)
103
+ : accessTokenExpires;
104
+ const expiresIn = expiryTime - now;
105
+ const isExpired = expiresIn <= 0;
106
+ const needsRefresh = expiresIn <= 300; // 5 minutes buffer
107
+ // Check if we have refresh capability (check normalized field name first)
108
+ const hasRefreshToken = !!(session?.idpRefreshToken || session?.refreshToken || token.refreshToken);
109
+ // CLEAR NAMING: Tenant-wide 2FA requirement from client config
110
+ const tenantRequiresTwoFactor = await getTenantRequiresTwoFactor();
111
+ // CRITICAL: Check if MFA has expired (2FA TTL enforcement)
112
+ // The session may have mfaVerified=true from days ago, but if mfaExpiresAt
113
+ // has passed, we must treat 2FA as incomplete to force re-verification.
114
+ const mfaExpiresAt = session?.mfaExpiresAt || 0;
115
+ const mfaExpired = mfaExpiresAt > 0 && mfaExpiresAt < Date.now();
116
+ // Check mfaVerified (normalized name) with fallback to twoFactorComplete for compatibility
117
+ const mfaVerifiedInSession = session?.mfaVerified ?? session?.twoFactorComplete ?? false;
118
+ // DEBUG: Log what we're reading from the session
119
+ console.log('[VIABILITY] Session 2FA state:', {
120
+ sessionToken: sessionToken?.substring(0, 8) + '...',
121
+ 'session.mfaVerified': session?.mfaVerified,
122
+ 'session.twoFactorComplete': session?.twoFactorComplete,
123
+ mfaVerifiedInSession,
124
+ mfaExpiresAt,
125
+ mfaExpired,
126
+ hasRefreshToken,
127
+ 'session.idpRefreshToken': !!session?.idpRefreshToken,
128
+ 'session.refreshToken': !!session?.refreshToken,
129
+ });
130
+ // CLEAR NAMING: User has completed 2FA requirements if: they verified AND it hasn't expired
131
+ const userHasCompletedTenantTwoFactorRequirements = mfaVerifiedInSession && !mfaExpired;
132
+ // userStillNeedsTwoFactor = inverse of completed (matches session callback logic)
133
+ const userStillNeedsTwoFactor = !userHasCompletedTenantTwoFactorRequirements;
134
+ if (mfaExpired && mfaVerifiedInSession) {
135
+ console.warn('[VIABILITY] MFA expired - forcing 2FA re-verification');
136
+ }
137
+ if (isExpired) {
138
+ return server_1.NextResponse.json({
139
+ viable: false,
140
+ needsRefresh: hasRefreshToken,
141
+ expiresIn: 0,
142
+ hasRefreshToken,
143
+ authenticated: true,
144
+ sessionToken,
145
+ // Clear names
146
+ tenantRequiresTwoFactor,
147
+ userHasCompletedTenantTwoFactorRequirements,
148
+ userStillNeedsTwoFactor,
149
+ // Legacy names for backwards compatibility
150
+ requires2FA: tenantRequiresTwoFactor,
151
+ twoFactorComplete: userHasCompletedTenantTwoFactorRequirements,
152
+ accessTokenExpired: true,
153
+ reason: 'Token expired',
154
+ // RBAC fields
155
+ roles: session?.roles || [],
156
+ clientId: session?.idpClientId || process.env.IDP_CLIENT_ID || '',
157
+ });
158
+ }
159
+ return server_1.NextResponse.json({
160
+ viable: true,
161
+ needsRefresh,
162
+ expiresIn,
163
+ hasRefreshToken,
164
+ authenticated: true,
165
+ sessionToken,
166
+ // Clear names
167
+ tenantRequiresTwoFactor,
168
+ userHasCompletedTenantTwoFactorRequirements,
169
+ userStillNeedsTwoFactor,
170
+ // Legacy names for backwards compatibility
171
+ requires2FA: tenantRequiresTwoFactor,
172
+ twoFactorComplete: userHasCompletedTenantTwoFactorRequirements,
173
+ accessTokenExpired: false,
174
+ expiresAt: new Date(expiryTime * 1000).toISOString(),
175
+ // RBAC fields
176
+ roles: session?.roles || [],
177
+ clientId: session?.idpClientId || process.env.IDP_CLIENT_ID || '',
178
+ });
179
+ }
180
+ catch (error) {
181
+ console.error('[VIABILITY_ROUTE] Error checking session viability:', error);
182
+ return server_1.NextResponse.json({
183
+ viable: false,
184
+ needsRefresh: false,
185
+ authenticated: false,
186
+ error: 'Failed to check session',
187
+ details: error instanceof Error ? error.message : 'Unknown error'
188
+ }, { status: 500 });
189
+ }
190
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @payez/next-mvp Route Module Exports
3
+ *
4
+ * Ready-to-use route handlers for quick integration
5
+ *
6
+ * @version 2.3.0
7
+ * @since auth-ready-v2
8
+ */
9
+ export * from './auth';
10
+ export * from './account';
11
+ export * as auth from './auth';
12
+ export * as account from './account';