@payez/next-mvp 3.9.1 → 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 (147) 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 -1020
  39. package/dist/client/fetch-with-auth.js +2 -2
  40. package/dist/components/SessionSync.js +121 -119
  41. package/dist/components/account/MobileNavDrawer.js +64 -64
  42. package/dist/components/account/UserAvatarMenu.js +91 -88
  43. package/dist/components/admin/VibeAdminLayout.js +71 -69
  44. package/dist/hooks/useAuth.js +9 -7
  45. package/dist/hooks/useAuthSettings.js +93 -93
  46. package/dist/hooks/useAvailableProviders.d.ts +43 -45
  47. package/dist/hooks/useAvailableProviders.js +112 -108
  48. package/dist/hooks/useSessionExpiration.d.ts +2 -3
  49. package/dist/hooks/useSessionExpiration.js +2 -2
  50. package/dist/hooks/useViabilitySession.js +3 -2
  51. package/dist/index.js +4 -6
  52. package/dist/lib/app-slug.d.ts +95 -95
  53. package/dist/lib/app-slug.js +172 -172
  54. package/dist/lib/standardized-client-api.js +10 -5
  55. package/dist/lib/startup-init.js +21 -25
  56. package/dist/lib/test-aware-get-token.js +86 -81
  57. package/dist/lib/token-lifecycle.d.ts +78 -52
  58. package/dist/lib/token-lifecycle.js +360 -398
  59. package/dist/pages/admin-login/page.js +73 -83
  60. package/dist/pages/client-admin/ClientSiteAdminPage.js +179 -177
  61. package/dist/pages/login/page.js +202 -211
  62. package/dist/pages/showcase/ShowcasePage.js +142 -140
  63. package/dist/pages/test-env/EmergencyLogoutPage.js +99 -98
  64. package/dist/pages/test-env/JwtInspectPage.js +116 -114
  65. package/dist/pages/test-env/RefreshTokenPage.js +4 -2
  66. package/dist/pages/test-env/TestEnvPage.js +51 -49
  67. package/dist/pages/verify-code/page.js +412 -408
  68. package/dist/routes/auth/logout.d.ts +31 -31
  69. package/dist/routes/auth/logout.js +98 -113
  70. package/dist/routes/auth/nextauth.d.ts +14 -11
  71. package/dist/routes/auth/nextauth.js +25 -57
  72. package/dist/routes/auth/session.js +157 -179
  73. package/dist/routes/auth/viability.js +190 -201
  74. package/dist/server/auth.d.ts +50 -0
  75. package/dist/server/auth.js +62 -0
  76. package/dist/stores/authStore.js +19 -23
  77. package/dist/utils/logout.js +5 -5
  78. package/package.json +1 -3
  79. package/src/api/auth-handler.ts +550 -549
  80. package/src/api-handlers/account/change-password.ts +5 -8
  81. package/src/api-handlers/admin/analytics.ts +4 -6
  82. package/src/api-handlers/admin/audit.ts +5 -7
  83. package/src/api-handlers/admin/index.ts +1 -2
  84. package/src/api-handlers/admin/redis-sessions.ts +6 -8
  85. package/src/api-handlers/admin/sessions.ts +5 -7
  86. package/src/api-handlers/admin/site-logs.ts +8 -10
  87. package/src/api-handlers/admin/stats.ts +4 -6
  88. package/src/api-handlers/admin/users.ts +5 -7
  89. package/src/api-handlers/admin/vibe-data.ts +10 -12
  90. package/src/api-handlers/auth/refresh.ts +5 -7
  91. package/src/api-handlers/auth/signout.ts +5 -6
  92. package/src/api-handlers/auth/status.ts +4 -7
  93. package/src/api-handlers/auth/update-session.ts +123 -125
  94. package/src/api-handlers/auth/verify-code.ts +9 -13
  95. package/src/api-handlers/session/viability.ts +10 -47
  96. package/src/api-handlers/test/force-expire.ts +4 -11
  97. package/src/auth/auth-decision.ts +1 -1
  98. package/src/auth/better-auth.ts +138 -141
  99. package/src/auth/route-config.ts +219 -219
  100. package/src/auth/utils/token-utils.ts +0 -1
  101. package/src/client/AuthContext.tsx +6 -2
  102. package/src/client/fetch-with-auth.ts +47 -47
  103. package/src/components/SessionSync.tsx +6 -5
  104. package/src/components/account/MobileNavDrawer.tsx +3 -3
  105. package/src/components/account/UserAvatarMenu.tsx +6 -3
  106. package/src/components/admin/VibeAdminLayout.tsx +4 -2
  107. package/src/config/logger.ts +1 -1
  108. package/src/hooks/useAuth.ts +117 -115
  109. package/src/hooks/useAuthSettings.ts +2 -2
  110. package/src/hooks/useAvailableProviders.ts +9 -5
  111. package/src/hooks/useSessionExpiration.ts +101 -102
  112. package/src/hooks/useViabilitySession.ts +336 -335
  113. package/src/index.ts +60 -63
  114. package/src/lib/api-handler.ts +0 -1
  115. package/src/lib/app-slug.ts +6 -6
  116. package/src/lib/standardized-client-api.ts +901 -895
  117. package/src/lib/startup-init.ts +243 -247
  118. package/src/lib/test-aware-get-token.ts +22 -12
  119. package/src/lib/token-lifecycle.ts +12 -53
  120. package/src/pages/admin-login/page.tsx +9 -17
  121. package/src/pages/client-admin/ClientSiteAdminPage.tsx +4 -2
  122. package/src/pages/login/page.tsx +21 -28
  123. package/src/pages/showcase/ShowcasePage.tsx +4 -2
  124. package/src/pages/test-env/EmergencyLogoutPage.tsx +7 -6
  125. package/src/pages/test-env/JwtInspectPage.tsx +5 -3
  126. package/src/pages/test-env/RefreshTokenPage.tsx +157 -155
  127. package/src/pages/test-env/TestEnvPage.tsx +4 -2
  128. package/src/pages/verify-code/page.tsx +10 -6
  129. package/src/routes/auth/logout.ts +7 -25
  130. package/src/routes/auth/nextauth.ts +45 -71
  131. package/src/routes/auth/session.ts +25 -50
  132. package/src/routes/auth/viability.ts +7 -19
  133. package/src/server/auth.ts +60 -0
  134. package/src/stores/authStore.ts +1899 -1904
  135. package/src/utils/logout.ts +30 -30
  136. package/src/auth/auth-options.ts +0 -237
  137. package/src/auth/callbacks/index.ts +0 -7
  138. package/src/auth/callbacks/jwt.ts +0 -382
  139. package/src/auth/callbacks/session.ts +0 -243
  140. package/src/auth/callbacks/signin.ts +0 -56
  141. package/src/auth/events/index.ts +0 -5
  142. package/src/auth/events/signout.ts +0 -33
  143. package/src/auth/providers/credentials.ts +0 -256
  144. package/src/auth/providers/index.ts +0 -6
  145. package/src/auth/providers/oauth.ts +0 -114
  146. package/src/lib/nextauth-secret.ts +0 -121
  147. package/src/types/next-auth.d.ts +0 -15
@@ -1,31 +1,31 @@
1
- /**
2
- * Ready-to-Use Logout Route
3
- *
4
- * Provides a pre-configured logout handler that properly cleans up
5
- * sessions and revokes tokens.
6
- *
7
- * @example
8
- * ```typescript
9
- * // app/api/auth/logout/route.ts
10
- * export { POST } from '@payez/next-mvp/routes/auth/logout';
11
- * ```
12
- *
13
- * @version 2.0.0
14
- * @since auth-ready-v2
15
- */
16
- import { NextRequest, NextResponse } from 'next/server';
17
- /**
18
- * POST /api/auth/logout - Sign out and clean up session
19
- *
20
- * Performs complete logout:
21
- * 1. Revokes tokens at IDP (if refresh token available)
22
- * 2. Deletes session from store
23
- * 3. Clears NextAuth session cookie
24
- */
25
- export declare function POST(req: NextRequest): Promise<NextResponse<{
26
- success: boolean;
27
- message: string;
28
- }> | NextResponse<{
29
- error: string;
30
- details: string;
31
- }>>;
1
+ /**
2
+ * Ready-to-Use Logout Route
3
+ *
4
+ * Provides a pre-configured logout handler that properly cleans up
5
+ * sessions and revokes tokens.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // app/api/auth/logout/route.ts
10
+ * export { POST } from '@payez/next-mvp/routes/auth/logout';
11
+ * ```
12
+ *
13
+ * @version 2.0.0
14
+ * @since auth-ready-v2
15
+ */
16
+ import { NextRequest, NextResponse } from 'next/server';
17
+ /**
18
+ * POST /api/auth/logout - Sign out and clean up session
19
+ *
20
+ * Performs complete logout:
21
+ * 1. Revokes tokens at IDP (if refresh token available)
22
+ * 2. Deletes session from store
23
+ * 3. Clears session cookies
24
+ */
25
+ export declare function POST(req: NextRequest): Promise<NextResponse<{
26
+ success: boolean;
27
+ message: string;
28
+ }> | NextResponse<{
29
+ error: string;
30
+ details: string;
31
+ }>>;
@@ -1,113 +1,98 @@
1
- "use strict";
2
- /**
3
- * Ready-to-Use Logout Route
4
- *
5
- * Provides a pre-configured logout handler that properly cleans up
6
- * sessions and revokes tokens.
7
- *
8
- * @example
9
- * ```typescript
10
- * // app/api/auth/logout/route.ts
11
- * export { POST } from '@payez/next-mvp/routes/auth/logout';
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 server_1 = require("next/server");
20
- const jwt_1 = require("next-auth/jwt");
21
- const session_store_1 = require("../../lib/session-store");
22
- const app_slug_1 = require("../../lib/app-slug");
23
- const idp_client_config_1 = require("../../lib/idp-client-config");
24
- const site_logger_1 = require("../../lib/site-logger");
25
- async function getConfig() {
26
- const idpConfig = await (0, idp_client_config_1.getIDPClientConfig)();
27
- const idpBaseUrl = process.env.IDP_URL;
28
- if (!idpBaseUrl) {
29
- throw new Error('[IDP_URL] FATAL: IDP_URL environment variable is REQUIRED.');
30
- }
31
- return {
32
- nextAuthSecret: idpConfig.nextAuthSecret || '',
33
- idpBaseUrl,
34
- clientId: process.env.CLIENT_ID || process.env.NEXT_PUBLIC_IDP_CLIENT_ID || '',
35
- };
36
- }
37
- /**
38
- * POST /api/auth/logout - Sign out and clean up session
39
- *
40
- * Performs complete logout:
41
- * 1. Revokes tokens at IDP (if refresh token available)
42
- * 2. Deletes session from store
43
- * 3. Clears NextAuth session cookie
44
- */
45
- async function POST(req) {
46
- const { nextAuthSecret, idpBaseUrl, clientId } = await getConfig();
47
- try {
48
- const token = await (0, jwt_1.getToken)({ req, secret: nextAuthSecret, cookieName: (0, app_slug_1.getJwtCookieName)() });
49
- if (!token) {
50
- // Already logged out
51
- return server_1.NextResponse.json({
52
- success: true,
53
- message: 'No active session'
54
- });
55
- }
56
- // Support both field names: sessionToken (auth.ts JWT) and redisSessionId (legacy)
57
- const sessionId = token.sessionToken || token.redisSessionId;
58
- // Delete session from store (this also removes the refresh token)
59
- if (sessionId) {
60
- try {
61
- await (0, session_store_1.deleteSession)(sessionId);
62
- console.info('[LOGOUT_ROUTE] Session deleted from store');
63
- }
64
- catch (error) {
65
- console.warn('[LOGOUT_ROUTE] Failed to delete session:', error);
66
- }
67
- }
68
- // Log logout event (fire-and-forget)
69
- const userId = token.sub || token.idpUserId;
70
- if (userId) {
71
- site_logger_1.siteEvents.logout({
72
- user_id: userId,
73
- session_id: sessionId,
74
- trigger: 'user',
75
- url: '/api/auth/logout',
76
- user_agent: req.headers.get('user-agent') || undefined,
77
- ip_address: (0, site_logger_1.getClientIp)(req.headers) || undefined,
78
- });
79
- }
80
- // Build response that clears NextAuth cookies
81
- const response = server_1.NextResponse.json({
82
- success: true,
83
- message: 'Logged out successfully'
84
- });
85
- // Clear NextAuth session cookies (using app-slug prefixed names)
86
- const cookieNames = [
87
- (0, app_slug_1.getSessionCookieName)(),
88
- (0, app_slug_1.getSecureSessionCookieName)(),
89
- (0, app_slug_1.getCsrfCookieName)(),
90
- (0, app_slug_1.getSecureCsrfCookieName)(),
91
- (0, app_slug_1.getCallbackUrlCookieName)(),
92
- `__Secure-${(0, app_slug_1.getCallbackUrlCookieName)()}`,
93
- ];
94
- // Clear each cookie by setting it with maxAge 0
95
- cookieNames.forEach(name => {
96
- response.cookies.set(name, '', {
97
- maxAge: 0,
98
- path: '/',
99
- httpOnly: true,
100
- secure: process.env.NODE_ENV === 'production',
101
- sameSite: 'lax'
102
- });
103
- });
104
- return response;
105
- }
106
- catch (error) {
107
- console.error('[LOGOUT_ROUTE] Error during logout:', error);
108
- return server_1.NextResponse.json({
109
- error: 'Failed to logout',
110
- details: error instanceof Error ? error.message : 'Unknown error'
111
- }, { status: 500 });
112
- }
113
- }
1
+ "use strict";
2
+ /**
3
+ * Ready-to-Use Logout Route
4
+ *
5
+ * Provides a pre-configured logout handler that properly cleans up
6
+ * sessions and revokes tokens.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // app/api/auth/logout/route.ts
11
+ * export { POST } from '@payez/next-mvp/routes/auth/logout';
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 server_1 = require("next/server");
20
+ const auth_1 = require("../../server/auth");
21
+ const session_store_1 = require("../../lib/session-store");
22
+ const app_slug_1 = require("../../lib/app-slug");
23
+ const site_logger_1 = require("../../lib/site-logger");
24
+ /**
25
+ * POST /api/auth/logout - Sign out and clean up session
26
+ *
27
+ * Performs complete logout:
28
+ * 1. Revokes tokens at IDP (if refresh token available)
29
+ * 2. Deletes session from store
30
+ * 3. Clears session cookies
31
+ */
32
+ async function POST(req) {
33
+ try {
34
+ const session = await (0, auth_1.getSession)(req);
35
+ if (!session) {
36
+ // Already logged out
37
+ return server_1.NextResponse.json({
38
+ success: true,
39
+ message: 'No active session'
40
+ });
41
+ }
42
+ const sessionId = session.session?.token;
43
+ // Delete session from store (this also removes the refresh token)
44
+ if (sessionId) {
45
+ try {
46
+ await (0, session_store_1.deleteSession)(sessionId);
47
+ console.info('[LOGOUT_ROUTE] Session deleted from store');
48
+ }
49
+ catch (error) {
50
+ console.warn('[LOGOUT_ROUTE] Failed to delete session:', error);
51
+ }
52
+ }
53
+ // Log logout event (fire-and-forget)
54
+ const userId = session.user?.id;
55
+ if (userId) {
56
+ site_logger_1.siteEvents.logout({
57
+ user_id: userId,
58
+ session_id: sessionId,
59
+ trigger: 'user',
60
+ url: '/api/auth/logout',
61
+ user_agent: req.headers.get('user-agent') || undefined,
62
+ ip_address: (0, site_logger_1.getClientIp)(req.headers) || undefined,
63
+ });
64
+ }
65
+ // Build response that clears session cookies
66
+ const response = server_1.NextResponse.json({
67
+ success: true,
68
+ message: 'Logged out successfully'
69
+ });
70
+ // Clear NextAuth session cookies (using app-slug prefixed names)
71
+ const cookieNames = [
72
+ (0, app_slug_1.getSessionCookieName)(),
73
+ (0, app_slug_1.getSecureSessionCookieName)(),
74
+ (0, app_slug_1.getCsrfCookieName)(),
75
+ (0, app_slug_1.getSecureCsrfCookieName)(),
76
+ (0, app_slug_1.getCallbackUrlCookieName)(),
77
+ `__Secure-${(0, app_slug_1.getCallbackUrlCookieName)()}`,
78
+ ];
79
+ // Clear each cookie by setting it with maxAge 0
80
+ cookieNames.forEach(name => {
81
+ response.cookies.set(name, '', {
82
+ maxAge: 0,
83
+ path: '/',
84
+ httpOnly: true,
85
+ secure: process.env.NODE_ENV === 'production',
86
+ sameSite: 'lax'
87
+ });
88
+ });
89
+ return response;
90
+ }
91
+ catch (error) {
92
+ console.error('[LOGOUT_ROUTE] Error during logout:', error);
93
+ return server_1.NextResponse.json({
94
+ error: 'Failed to logout',
95
+ details: error instanceof Error ? error.message : 'Unknown error'
96
+ }, { status: 500 });
97
+ }
98
+ }
@@ -1,19 +1,22 @@
1
1
  /**
2
- * Ready-to-Use NextAuth Route Handler
2
+ * Ready-to-Use Auth Route Handler (Better Auth)
3
3
  *
4
- * Provides a pre-configured NextAuth handler that uses dynamic OAuth providers
5
- * loaded from IDP at startup via getAuthOptions().
4
+ * Provides a pre-configured Better Auth handler that uses dynamic OAuth providers
5
+ * loaded from IDP at startup.
6
6
  *
7
- * @version 2.2.0 - Dynamic provider loading from IDP
8
- * @since auth-ready-v2-hotfix
7
+ * Replaces the former NextAuth handler. The file name is kept as nextauth.ts
8
+ * to avoid breaking re-exports in routes/auth/index.ts.
9
+ *
10
+ * @version 4.0.0 - Better Auth migration
11
+ * @since better-auth-4.0
9
12
  */
10
13
  /**
11
- * GET handler for NextAuth
12
- * Uses async factory to get dynamic providers from IDP
14
+ * GET handler for auth routes
15
+ * Delegates to Better Auth instance.
13
16
  */
14
- export declare function GET(request: Request, context: any): Promise<any>;
17
+ export declare function GET(request: Request): Promise<Response>;
15
18
  /**
16
- * POST handler for NextAuth
17
- * Uses async factory to get dynamic providers from IDP
19
+ * POST handler for auth routes
20
+ * Delegates to Better Auth instance.
18
21
  */
19
- export declare function POST(request: Request, context: any): Promise<any>;
22
+ export declare function POST(request: Request): Promise<Response>;
@@ -1,72 +1,40 @@
1
1
  "use strict";
2
2
  /**
3
- * Ready-to-Use NextAuth Route Handler
3
+ * Ready-to-Use Auth Route Handler (Better Auth)
4
4
  *
5
- * Provides a pre-configured NextAuth handler that uses dynamic OAuth providers
6
- * loaded from IDP at startup via getAuthOptions().
5
+ * Provides a pre-configured Better Auth handler that uses dynamic OAuth providers
6
+ * loaded from IDP at startup.
7
7
  *
8
- * @version 2.2.0 - Dynamic provider loading from IDP
9
- * @since auth-ready-v2-hotfix
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
10
13
  */
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.GET = GET;
16
16
  exports.POST = POST;
17
- const next_auth_1 = __importDefault(require("next-auth"));
18
- const auth_options_1 = require("../../auth/auth-options");
19
- // Cached handler - built once with dynamic providers
20
- let cachedHandler = null;
21
- let handlerPromise = null;
17
+ const better_auth_1 = require("../../auth/better-auth");
18
+ const server_1 = require("next/server");
22
19
  /**
23
- * Get or build the NextAuth handler with dynamic providers.
24
- * Uses caching to avoid rebuilding on every request.
20
+ * GET handler for auth routes
21
+ * Delegates to Better Auth instance.
25
22
  */
26
- async function getHandler() {
27
- // Return cached if available
28
- if (cachedHandler) {
29
- return cachedHandler;
30
- }
31
- // Prevent concurrent builds
32
- if (handlerPromise) {
33
- return handlerPromise;
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 });
34
27
  }
35
- handlerPromise = (async () => {
36
- try {
37
- // Try to get dynamic auth options from IDP
38
- const options = await (0, auth_options_1.getAuthOptions)();
39
- console.log('[NEXTAUTH_ROUTE] Built handler with dynamic providers');
40
- cachedHandler = (0, next_auth_1.default)(options);
41
- return cachedHandler;
42
- }
43
- catch (error) {
44
- // Fallback to static options if IDP unavailable
45
- console.warn('[NEXTAUTH_ROUTE] Failed to get dynamic options, using static fallback:', {
46
- error: error instanceof Error ? error.message : String(error)
47
- });
48
- cachedHandler = (0, next_auth_1.default)(auth_options_1.authOptions);
49
- return cachedHandler;
50
- }
51
- finally {
52
- handlerPromise = null;
53
- }
54
- })();
55
- return handlerPromise;
56
- }
57
- /**
58
- * GET handler for NextAuth
59
- * Uses async factory to get dynamic providers from IDP
60
- */
61
- async function GET(request, context) {
62
- const handler = await getHandler();
63
- return handler(request, context);
28
+ return handler.GET(request);
64
29
  }
65
30
  /**
66
- * POST handler for NextAuth
67
- * Uses async factory to get dynamic providers from IDP
31
+ * POST handler for auth routes
32
+ * Delegates to Better Auth instance.
68
33
  */
69
- async function POST(request, context) {
70
- const handler = await getHandler();
71
- return handler(request, context);
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);
72
40
  }