@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.
- package/dist/api/auth-handler.d.ts +1 -2
- package/dist/api/auth-handler.js +9 -9
- package/dist/api-handlers/account/change-password.js +110 -112
- package/dist/api-handlers/admin/analytics.d.ts +19 -20
- package/dist/api-handlers/admin/analytics.js +378 -379
- package/dist/api-handlers/admin/audit.d.ts +19 -20
- package/dist/api-handlers/admin/audit.js +213 -214
- package/dist/api-handlers/admin/index.d.ts +21 -22
- package/dist/api-handlers/admin/index.js +42 -43
- package/dist/api-handlers/admin/redis-sessions.d.ts +35 -36
- package/dist/api-handlers/admin/redis-sessions.js +203 -204
- package/dist/api-handlers/admin/sessions.d.ts +20 -21
- package/dist/api-handlers/admin/sessions.js +283 -284
- package/dist/api-handlers/admin/site-logs.d.ts +45 -46
- package/dist/api-handlers/admin/site-logs.js +317 -318
- package/dist/api-handlers/admin/stats.d.ts +20 -21
- package/dist/api-handlers/admin/stats.js +239 -240
- package/dist/api-handlers/admin/users.d.ts +19 -20
- package/dist/api-handlers/admin/users.js +221 -222
- package/dist/api-handlers/admin/vibe-data.d.ts +79 -80
- package/dist/api-handlers/admin/vibe-data.js +267 -268
- package/dist/api-handlers/auth/refresh.js +633 -635
- package/dist/api-handlers/auth/signout.js +186 -187
- package/dist/api-handlers/auth/status.js +4 -7
- package/dist/api-handlers/auth/update-session.d.ts +1 -1
- package/dist/api-handlers/auth/update-session.js +12 -14
- package/dist/api-handlers/auth/verify-code.d.ts +43 -43
- package/dist/api-handlers/auth/verify-code.js +90 -94
- package/dist/api-handlers/session/viability.js +114 -146
- package/dist/api-handlers/test/force-expire.js +59 -65
- package/dist/auth/auth-decision.js +182 -182
- package/dist/auth/better-auth.d.ts +3 -6
- package/dist/auth/better-auth.js +3 -6
- package/dist/auth/route-config.js +2 -2
- package/dist/auth/utils/token-utils.d.ts +83 -84
- package/dist/auth/utils/token-utils.js +218 -219
- package/dist/client/AuthContext.js +115 -112
- package/dist/client/better-auth-client.d.ts +1020 -1020
- package/dist/client/fetch-with-auth.js +2 -2
- package/dist/components/SessionSync.js +121 -119
- package/dist/components/account/MobileNavDrawer.js +64 -64
- package/dist/components/account/UserAvatarMenu.js +91 -88
- package/dist/components/admin/VibeAdminLayout.js +71 -69
- package/dist/hooks/useAuth.js +9 -7
- package/dist/hooks/useAuthSettings.js +93 -93
- package/dist/hooks/useAvailableProviders.d.ts +43 -45
- package/dist/hooks/useAvailableProviders.js +112 -108
- package/dist/hooks/useSessionExpiration.d.ts +2 -3
- package/dist/hooks/useSessionExpiration.js +2 -2
- package/dist/hooks/useViabilitySession.js +3 -2
- package/dist/index.js +4 -6
- package/dist/lib/app-slug.d.ts +95 -95
- package/dist/lib/app-slug.js +172 -172
- package/dist/lib/standardized-client-api.js +10 -5
- package/dist/lib/startup-init.js +21 -25
- package/dist/lib/test-aware-get-token.js +86 -81
- package/dist/lib/token-lifecycle.d.ts +78 -52
- package/dist/lib/token-lifecycle.js +360 -398
- package/dist/pages/admin-login/page.js +73 -83
- package/dist/pages/client-admin/ClientSiteAdminPage.js +179 -177
- package/dist/pages/login/page.js +202 -211
- package/dist/pages/showcase/ShowcasePage.js +142 -140
- package/dist/pages/test-env/EmergencyLogoutPage.js +99 -98
- package/dist/pages/test-env/JwtInspectPage.js +116 -114
- package/dist/pages/test-env/RefreshTokenPage.js +4 -2
- package/dist/pages/test-env/TestEnvPage.js +51 -49
- package/dist/pages/verify-code/page.js +412 -408
- package/dist/routes/auth/logout.d.ts +31 -31
- package/dist/routes/auth/logout.js +98 -113
- package/dist/routes/auth/nextauth.d.ts +14 -11
- package/dist/routes/auth/nextauth.js +25 -57
- package/dist/routes/auth/session.js +157 -179
- package/dist/routes/auth/viability.js +190 -201
- package/dist/server/auth.d.ts +50 -0
- package/dist/server/auth.js +62 -0
- package/dist/stores/authStore.js +19 -23
- package/dist/utils/logout.js +5 -5
- package/package.json +1 -3
- package/src/api/auth-handler.ts +550 -549
- package/src/api-handlers/account/change-password.ts +5 -8
- package/src/api-handlers/admin/analytics.ts +4 -6
- package/src/api-handlers/admin/audit.ts +5 -7
- package/src/api-handlers/admin/index.ts +1 -2
- package/src/api-handlers/admin/redis-sessions.ts +6 -8
- package/src/api-handlers/admin/sessions.ts +5 -7
- package/src/api-handlers/admin/site-logs.ts +8 -10
- package/src/api-handlers/admin/stats.ts +4 -6
- package/src/api-handlers/admin/users.ts +5 -7
- package/src/api-handlers/admin/vibe-data.ts +10 -12
- package/src/api-handlers/auth/refresh.ts +5 -7
- package/src/api-handlers/auth/signout.ts +5 -6
- package/src/api-handlers/auth/status.ts +4 -7
- package/src/api-handlers/auth/update-session.ts +123 -125
- package/src/api-handlers/auth/verify-code.ts +9 -13
- package/src/api-handlers/session/viability.ts +10 -47
- package/src/api-handlers/test/force-expire.ts +4 -11
- package/src/auth/auth-decision.ts +1 -1
- package/src/auth/better-auth.ts +138 -141
- package/src/auth/route-config.ts +219 -219
- package/src/auth/utils/token-utils.ts +0 -1
- package/src/client/AuthContext.tsx +6 -2
- package/src/client/fetch-with-auth.ts +47 -47
- package/src/components/SessionSync.tsx +6 -5
- package/src/components/account/MobileNavDrawer.tsx +3 -3
- package/src/components/account/UserAvatarMenu.tsx +6 -3
- package/src/components/admin/VibeAdminLayout.tsx +4 -2
- package/src/config/logger.ts +1 -1
- package/src/hooks/useAuth.ts +117 -115
- package/src/hooks/useAuthSettings.ts +2 -2
- package/src/hooks/useAvailableProviders.ts +9 -5
- package/src/hooks/useSessionExpiration.ts +101 -102
- package/src/hooks/useViabilitySession.ts +336 -335
- package/src/index.ts +60 -63
- package/src/lib/api-handler.ts +0 -1
- package/src/lib/app-slug.ts +6 -6
- package/src/lib/standardized-client-api.ts +901 -895
- package/src/lib/startup-init.ts +243 -247
- package/src/lib/test-aware-get-token.ts +22 -12
- package/src/lib/token-lifecycle.ts +12 -53
- package/src/pages/admin-login/page.tsx +9 -17
- package/src/pages/client-admin/ClientSiteAdminPage.tsx +4 -2
- package/src/pages/login/page.tsx +21 -28
- package/src/pages/showcase/ShowcasePage.tsx +4 -2
- package/src/pages/test-env/EmergencyLogoutPage.tsx +7 -6
- package/src/pages/test-env/JwtInspectPage.tsx +5 -3
- package/src/pages/test-env/RefreshTokenPage.tsx +157 -155
- package/src/pages/test-env/TestEnvPage.tsx +4 -2
- package/src/pages/verify-code/page.tsx +10 -6
- package/src/routes/auth/logout.ts +7 -25
- package/src/routes/auth/nextauth.ts +45 -71
- package/src/routes/auth/session.ts +25 -50
- package/src/routes/auth/viability.ts +7 -19
- package/src/server/auth.ts +60 -0
- package/src/stores/authStore.ts +1899 -1904
- package/src/utils/logout.ts +30 -30
- package/src/auth/auth-options.ts +0 -237
- package/src/auth/callbacks/index.ts +0 -7
- package/src/auth/callbacks/jwt.ts +0 -382
- package/src/auth/callbacks/session.ts +0 -243
- package/src/auth/callbacks/signin.ts +0 -56
- package/src/auth/events/index.ts +0 -5
- package/src/auth/events/signout.ts +0 -33
- package/src/auth/providers/credentials.ts +0 -256
- package/src/auth/providers/index.ts +0 -6
- package/src/auth/providers/oauth.ts +0 -114
- package/src/lib/nextauth-secret.ts +0 -121
- package/src/types/next-auth.d.ts +0 -15
|
@@ -1,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
|
|
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
|
|
21
|
-
const session_store_1 = require("../../lib/session-store");
|
|
22
|
-
const app_slug_1 = require("../../lib/app-slug");
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
|
2
|
+
* Ready-to-Use Auth Route Handler (Better Auth)
|
|
3
3
|
*
|
|
4
|
-
* Provides a pre-configured
|
|
5
|
-
* loaded from IDP at startup
|
|
4
|
+
* Provides a pre-configured Better Auth handler that uses dynamic OAuth providers
|
|
5
|
+
* loaded from IDP at startup.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
|
12
|
-
*
|
|
14
|
+
* GET handler for auth routes
|
|
15
|
+
* Delegates to Better Auth instance.
|
|
13
16
|
*/
|
|
14
|
-
export declare function GET(request: Request
|
|
17
|
+
export declare function GET(request: Request): Promise<Response>;
|
|
15
18
|
/**
|
|
16
|
-
* POST handler for
|
|
17
|
-
*
|
|
19
|
+
* POST handler for auth routes
|
|
20
|
+
* Delegates to Better Auth instance.
|
|
18
21
|
*/
|
|
19
|
-
export declare function POST(request: Request
|
|
22
|
+
export declare function POST(request: Request): Promise<Response>;
|
|
@@ -1,72 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Ready-to-Use
|
|
3
|
+
* Ready-to-Use Auth Route Handler (Better Auth)
|
|
4
4
|
*
|
|
5
|
-
* Provides a pre-configured
|
|
6
|
-
* loaded from IDP at startup
|
|
5
|
+
* Provides a pre-configured Better Auth handler that uses dynamic OAuth providers
|
|
6
|
+
* loaded from IDP at startup.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
18
|
-
const
|
|
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
|
-
*
|
|
24
|
-
*
|
|
20
|
+
* GET handler for auth routes
|
|
21
|
+
* Delegates to Better Auth instance.
|
|
25
22
|
*/
|
|
26
|
-
async function
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
return
|
|
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
|
-
|
|
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
|
|
67
|
-
*
|
|
31
|
+
* POST handler for auth routes
|
|
32
|
+
* Delegates to Better Auth instance.
|
|
68
33
|
*/
|
|
69
|
-
async function POST(request
|
|
70
|
-
const handler = await
|
|
71
|
-
|
|
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
|
}
|