@payez/next-mvp 3.9.0 → 4.0.0

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 (149) hide show
  1. package/dist/api/auth-handler.d.ts +1 -2
  2. package/dist/api/auth-handler.js +9 -9
  3. package/dist/api-handlers/account/change-password.js +110 -112
  4. package/dist/api-handlers/admin/analytics.d.ts +19 -20
  5. package/dist/api-handlers/admin/analytics.js +378 -379
  6. package/dist/api-handlers/admin/audit.d.ts +19 -20
  7. package/dist/api-handlers/admin/audit.js +213 -214
  8. package/dist/api-handlers/admin/index.d.ts +21 -22
  9. package/dist/api-handlers/admin/index.js +42 -43
  10. package/dist/api-handlers/admin/redis-sessions.d.ts +35 -36
  11. package/dist/api-handlers/admin/redis-sessions.js +203 -204
  12. package/dist/api-handlers/admin/sessions.d.ts +20 -21
  13. package/dist/api-handlers/admin/sessions.js +283 -284
  14. package/dist/api-handlers/admin/site-logs.d.ts +45 -46
  15. package/dist/api-handlers/admin/site-logs.js +317 -318
  16. package/dist/api-handlers/admin/stats.d.ts +20 -21
  17. package/dist/api-handlers/admin/stats.js +239 -240
  18. package/dist/api-handlers/admin/users.d.ts +19 -20
  19. package/dist/api-handlers/admin/users.js +221 -222
  20. package/dist/api-handlers/admin/vibe-data.d.ts +79 -80
  21. package/dist/api-handlers/admin/vibe-data.js +267 -268
  22. package/dist/api-handlers/auth/refresh.js +633 -635
  23. package/dist/api-handlers/auth/signout.js +186 -187
  24. package/dist/api-handlers/auth/status.js +4 -7
  25. package/dist/api-handlers/auth/update-session.d.ts +1 -1
  26. package/dist/api-handlers/auth/update-session.js +12 -14
  27. package/dist/api-handlers/auth/verify-code.d.ts +43 -43
  28. package/dist/api-handlers/auth/verify-code.js +90 -94
  29. package/dist/api-handlers/session/viability.js +114 -146
  30. package/dist/api-handlers/test/force-expire.js +59 -65
  31. package/dist/auth/auth-decision.js +182 -182
  32. package/dist/auth/better-auth.d.ts +3 -6
  33. package/dist/auth/better-auth.js +3 -6
  34. package/dist/auth/route-config.js +2 -2
  35. package/dist/auth/utils/token-utils.d.ts +83 -84
  36. package/dist/auth/utils/token-utils.js +218 -219
  37. package/dist/client/AuthContext.js +115 -112
  38. package/dist/client/better-auth-client.d.ts +1020 -961
  39. package/dist/client/better-auth-client.js +54 -7
  40. package/dist/client/fetch-with-auth.js +2 -2
  41. package/dist/components/SessionSync.js +121 -119
  42. package/dist/components/account/MobileNavDrawer.js +64 -64
  43. package/dist/components/account/UserAvatarMenu.js +91 -88
  44. package/dist/components/admin/VibeAdminLayout.js +71 -69
  45. package/dist/hooks/useAuth.js +9 -7
  46. package/dist/hooks/useAuthSettings.js +93 -93
  47. package/dist/hooks/useAvailableProviders.d.ts +43 -45
  48. package/dist/hooks/useAvailableProviders.js +112 -108
  49. package/dist/hooks/useSessionExpiration.d.ts +2 -3
  50. package/dist/hooks/useSessionExpiration.js +2 -2
  51. package/dist/hooks/useViabilitySession.js +3 -2
  52. package/dist/index.js +4 -6
  53. package/dist/lib/app-slug.d.ts +95 -95
  54. package/dist/lib/app-slug.js +172 -172
  55. package/dist/lib/standardized-client-api.js +10 -5
  56. package/dist/lib/startup-init.js +21 -25
  57. package/dist/lib/test-aware-get-token.js +86 -81
  58. package/dist/lib/token-lifecycle.d.ts +78 -52
  59. package/dist/lib/token-lifecycle.js +360 -398
  60. package/dist/pages/admin-login/page.js +73 -83
  61. package/dist/pages/client-admin/ClientSiteAdminPage.js +179 -177
  62. package/dist/pages/login/page.js +202 -211
  63. package/dist/pages/showcase/ShowcasePage.js +142 -140
  64. package/dist/pages/test-env/EmergencyLogoutPage.js +99 -98
  65. package/dist/pages/test-env/JwtInspectPage.js +116 -114
  66. package/dist/pages/test-env/RefreshTokenPage.js +4 -2
  67. package/dist/pages/test-env/TestEnvPage.js +51 -49
  68. package/dist/pages/verify-code/page.js +412 -408
  69. package/dist/routes/auth/logout.d.ts +31 -31
  70. package/dist/routes/auth/logout.js +98 -113
  71. package/dist/routes/auth/nextauth.d.ts +14 -11
  72. package/dist/routes/auth/nextauth.js +25 -57
  73. package/dist/routes/auth/session.js +157 -179
  74. package/dist/routes/auth/viability.js +190 -201
  75. package/dist/server/auth.d.ts +50 -0
  76. package/dist/server/auth.js +62 -0
  77. package/dist/stores/authStore.js +19 -23
  78. package/dist/utils/logout.js +5 -5
  79. package/package.json +1 -3
  80. package/src/api/auth-handler.ts +550 -549
  81. package/src/api-handlers/account/change-password.ts +5 -8
  82. package/src/api-handlers/admin/analytics.ts +4 -6
  83. package/src/api-handlers/admin/audit.ts +5 -7
  84. package/src/api-handlers/admin/index.ts +1 -2
  85. package/src/api-handlers/admin/redis-sessions.ts +6 -8
  86. package/src/api-handlers/admin/sessions.ts +5 -7
  87. package/src/api-handlers/admin/site-logs.ts +8 -10
  88. package/src/api-handlers/admin/stats.ts +4 -6
  89. package/src/api-handlers/admin/users.ts +5 -7
  90. package/src/api-handlers/admin/vibe-data.ts +10 -12
  91. package/src/api-handlers/auth/refresh.ts +5 -7
  92. package/src/api-handlers/auth/signout.ts +5 -6
  93. package/src/api-handlers/auth/status.ts +4 -7
  94. package/src/api-handlers/auth/update-session.ts +123 -125
  95. package/src/api-handlers/auth/verify-code.ts +9 -13
  96. package/src/api-handlers/session/viability.ts +10 -47
  97. package/src/api-handlers/test/force-expire.ts +4 -11
  98. package/src/auth/auth-decision.ts +1 -1
  99. package/src/auth/better-auth.ts +138 -141
  100. package/src/auth/route-config.ts +219 -219
  101. package/src/auth/utils/token-utils.ts +0 -1
  102. package/src/client/AuthContext.tsx +6 -2
  103. package/src/client/better-auth-client.ts +54 -7
  104. package/src/client/fetch-with-auth.ts +47 -47
  105. package/src/components/SessionSync.tsx +6 -5
  106. package/src/components/account/MobileNavDrawer.tsx +3 -3
  107. package/src/components/account/UserAvatarMenu.tsx +6 -3
  108. package/src/components/admin/VibeAdminLayout.tsx +4 -2
  109. package/src/config/logger.ts +1 -1
  110. package/src/hooks/useAuth.ts +117 -115
  111. package/src/hooks/useAuthSettings.ts +2 -2
  112. package/src/hooks/useAvailableProviders.ts +9 -5
  113. package/src/hooks/useSessionExpiration.ts +101 -102
  114. package/src/hooks/useViabilitySession.ts +336 -335
  115. package/src/index.ts +60 -63
  116. package/src/lib/api-handler.ts +0 -1
  117. package/src/lib/app-slug.ts +6 -6
  118. package/src/lib/standardized-client-api.ts +901 -895
  119. package/src/lib/startup-init.ts +243 -247
  120. package/src/lib/test-aware-get-token.ts +22 -12
  121. package/src/lib/token-lifecycle.ts +12 -53
  122. package/src/pages/admin-login/page.tsx +9 -17
  123. package/src/pages/client-admin/ClientSiteAdminPage.tsx +4 -2
  124. package/src/pages/login/page.tsx +21 -28
  125. package/src/pages/showcase/ShowcasePage.tsx +4 -2
  126. package/src/pages/test-env/EmergencyLogoutPage.tsx +7 -6
  127. package/src/pages/test-env/JwtInspectPage.tsx +5 -3
  128. package/src/pages/test-env/RefreshTokenPage.tsx +157 -155
  129. package/src/pages/test-env/TestEnvPage.tsx +4 -2
  130. package/src/pages/verify-code/page.tsx +10 -6
  131. package/src/routes/auth/logout.ts +7 -25
  132. package/src/routes/auth/nextauth.ts +45 -71
  133. package/src/routes/auth/session.ts +25 -50
  134. package/src/routes/auth/viability.ts +7 -19
  135. package/src/server/auth.ts +60 -0
  136. package/src/stores/authStore.ts +1899 -1904
  137. package/src/utils/logout.ts +30 -30
  138. package/src/auth/auth-options.ts +0 -237
  139. package/src/auth/callbacks/index.ts +0 -7
  140. package/src/auth/callbacks/jwt.ts +0 -382
  141. package/src/auth/callbacks/session.ts +0 -243
  142. package/src/auth/callbacks/signin.ts +0 -56
  143. package/src/auth/events/index.ts +0 -5
  144. package/src/auth/events/signout.ts +0 -33
  145. package/src/auth/providers/credentials.ts +0 -256
  146. package/src/auth/providers/index.ts +0 -6
  147. package/src/auth/providers/oauth.ts +0 -114
  148. package/src/lib/nextauth-secret.ts +0 -121
  149. package/src/types/next-auth.d.ts +0 -15
package/src/index.ts CHANGED
@@ -1,63 +1,60 @@
1
- // Type augmentation for NextAuth - included via ambient module declaration
2
- // Note: Type declarations are picked up automatically via tsconfig.json, no explicit import needed
3
-
4
- // NOTE: Server-only exports are NOT exported from the root to prevent bundling Node.js modules in client code.
5
- // Server-side code should import from subpath exports:
6
- // - Session management: import { sessionStore } from '@payez/next-mvp/lib/session-store'
7
- // - Redis client: import { redis } from '@payez/next-mvp/lib/redis'
8
- // - Token expiry: import { computeTokenExpiries } from '@payez/next-mvp/lib/token-expiry'
9
- // - Refresh validation: import { validateRefreshToken } from '@payez/next-mvp/lib/refresh-token-validator'
10
- // - Auth options: import { authOptions } from '@payez/next-mvp/auth/auth-options'
11
- // - Auth handler: import { createAuthHandler } from '@payez/next-mvp/api/auth-handler'
12
-
13
- // Client-safe exports only
14
-
15
- // Client-side utilities
16
- export { fetchWithAuth } from './client/fetch-with-auth';
17
-
18
- // Anonymous session hook (for pre-login preferences like theme)
19
- export { useAnonSession } from './client/useAnonSession';
20
- export type { AnonPreferences, AnonMetrics, AnonSession, UseAnonSessionReturn } from './client/useAnonSession';
21
-
22
- // Authentication Context and Hooks
23
- export { AuthProvider, useAuthConfig, useAuthMode, useFederatedProviders, useFederatedAuthEnabled, useTraditionalAuthEnabled } from './client/AuthContext';
24
- export type { AuthConfig } from './types/auth';
25
-
26
- // Route configuration (client-safe)
27
- export { makeAuthDecision } from './auth/auth-decision';
28
- export { isUnauthenticatedRoute, configurePublicRoutes, getRouteConfig } from './auth/route-config';
29
- export { createMvpMiddleware } from './middleware/create-middleware';
30
-
31
- // Account Components
32
- export { UserAvatarMenu, MobileNavDrawer } from './components/account';
33
- export type { UserAvatarMenuProps, MobileNavDrawerProps, NavItem, NavSection } from './components/account';
34
-
35
- // Admin Logging & Analytics (client-side components and hooks)
36
- export {
37
- ErrorMetricsCard,
38
- HealthMetricsCard,
39
- AuditLogViewer,
40
- AdminAnalyticsLayout,
41
- useErrorMetrics,
42
- useHealthMetrics,
43
- useAuditLog,
44
- useAdminAnalytics,
45
- getErrorMetrics,
46
- getHealthMetrics,
47
- writeAuditLog,
48
- queryAuditLog,
49
- } from './logging';
50
- export type {
51
- ErrorMetrics,
52
- HealthMetrics,
53
- AuditLogEntry,
54
- AuditLogQuery,
55
- AuditLogResponse,
56
- TimeRange,
57
- RouteError,
58
- LevelCount,
59
- CategoryCount,
60
- ErrorDetail,
61
- EndpointHealth,
62
- SlowRequest,
63
- } from './logging';
1
+ // NOTE: Server-only exports are NOT exported from the root to prevent bundling Node.js modules in client code.
2
+ // Server-side code should import from subpath exports:
3
+ // - Session management: import { sessionStore } from '@payez/next-mvp/lib/session-store'
4
+ // - Redis client: import { redis } from '@payez/next-mvp/lib/redis'
5
+ // - Token expiry: import { computeTokenExpiries } from '@payez/next-mvp/lib/token-expiry'
6
+ // - Refresh validation: import { validateRefreshToken } from '@payez/next-mvp/lib/refresh-token-validator'
7
+ // - Better Auth: import { createBetterAuthInstance } from '@payez/next-mvp/auth/better-auth'
8
+ // - Server auth: import { getSession } from '@payez/next-mvp/server/auth'
9
+
10
+ // Client-safe exports only
11
+
12
+ // Client-side utilities
13
+ export { fetchWithAuth } from './client/fetch-with-auth';
14
+
15
+ // Anonymous session hook (for pre-login preferences like theme)
16
+ export { useAnonSession } from './client/useAnonSession';
17
+ export type { AnonPreferences, AnonMetrics, AnonSession, UseAnonSessionReturn } from './client/useAnonSession';
18
+
19
+ // Authentication Context and Hooks
20
+ export { AuthProvider, useAuthConfig, useAuthMode, useFederatedProviders, useFederatedAuthEnabled, useTraditionalAuthEnabled } from './client/AuthContext';
21
+ export type { AuthConfig } from './types/auth';
22
+
23
+ // Route configuration (client-safe)
24
+ export { makeAuthDecision } from './auth/auth-decision';
25
+ export { isUnauthenticatedRoute, configurePublicRoutes, getRouteConfig } from './auth/route-config';
26
+ export { createMvpMiddleware } from './middleware/create-middleware';
27
+
28
+ // Account Components
29
+ export { UserAvatarMenu, MobileNavDrawer } from './components/account';
30
+ export type { UserAvatarMenuProps, MobileNavDrawerProps, NavItem, NavSection } from './components/account';
31
+
32
+ // Admin Logging & Analytics (client-side components and hooks)
33
+ export {
34
+ ErrorMetricsCard,
35
+ HealthMetricsCard,
36
+ AuditLogViewer,
37
+ AdminAnalyticsLayout,
38
+ useErrorMetrics,
39
+ useHealthMetrics,
40
+ useAuditLog,
41
+ useAdminAnalytics,
42
+ getErrorMetrics,
43
+ getHealthMetrics,
44
+ writeAuditLog,
45
+ queryAuditLog,
46
+ } from './logging';
47
+ export type {
48
+ ErrorMetrics,
49
+ HealthMetrics,
50
+ AuditLogEntry,
51
+ AuditLogQuery,
52
+ AuditLogResponse,
53
+ TimeRange,
54
+ RouteError,
55
+ LevelCount,
56
+ CategoryCount,
57
+ ErrorDetail,
58
+ EndpointHealth,
59
+ SlowRequest,
60
+ } from './logging';
@@ -14,7 +14,6 @@
14
14
  */
15
15
 
16
16
  import { NextRequest, NextResponse } from 'next/server';
17
- import { getToken } from 'next-auth/jwt';
18
17
  import { nanoid } from 'nanoid';
19
18
  import {
20
19
  getSession,
@@ -67,7 +67,7 @@ export function getRefreshLockPrefix(): string {
67
67
  // ============================================================================
68
68
  //
69
69
  // CRITICAL: The session cookie name MUST be consistent between:
70
- // 1. auth-options.ts (where NextAuth SETS the cookie)
70
+ // 1. better-auth.ts (where auth SETS the cookie)
71
71
  // 2. getToken() calls (where we READ the cookie)
72
72
  //
73
73
  // If these don't match, sessions will appear empty in one environment but
@@ -81,7 +81,7 @@ export function getRefreshLockPrefix(): string {
81
81
  * THE session cookie name - SINGLE SOURCE OF TRUTH.
82
82
  *
83
83
  * This is used by:
84
- * - auth-options.ts (cookies.sessionToken.name)
84
+ * - better-auth.ts (cookies.sessionToken.name)
85
85
  * - getToken() calls (cookieName parameter)
86
86
  * - getJwtCookieName() (alias for consistency)
87
87
  *
@@ -94,14 +94,14 @@ export function getSessionCookieName(): string {
94
94
  /**
95
95
  * Gets the JWT cookie name for getToken() calls.
96
96
  *
97
- * CRITICAL: This MUST match what auth-options.ts configures:
97
+ * CRITICAL: This MUST match what the auth config sets:
98
98
  * - Production: __Secure-{slug}.session-token
99
99
  * - Development: {slug}.session-token
100
100
  *
101
101
  * This is the cookie name that getToken() should use to READ the JWT.
102
102
  */
103
103
  export function getJwtCookieName(): string {
104
- // Must match auth-options.ts cookies.sessionToken.name logic
104
+ // Must match auth config cookies.sessionToken.name logic
105
105
  if (process.env.NODE_ENV === 'production') {
106
106
  return getSecureSessionCookieName();
107
107
  }
@@ -109,7 +109,7 @@ export function getJwtCookieName(): string {
109
109
  }
110
110
 
111
111
  /**
112
- * Validates that cookie names are consistent with auth-options.ts.
112
+ * Validates that cookie names are consistent with the auth config.
113
113
  * Call this at startup to catch mismatches early.
114
114
  */
115
115
  export function validateCookieNameConsistency(): void {
@@ -133,7 +133,7 @@ export function validateCookieNameConsistency(): void {
133
133
  *
134
134
  * WARNING: This is ONLY for clearing cookies during logout.
135
135
  * DO NOT use this for reading cookies - use getSessionCookieName().
136
- * NextAuth does NOT automatically use this prefix.
136
+ * Auth does NOT automatically use this prefix.
137
137
  *
138
138
  * Format: __Secure-{slug}.session-token
139
139
  */