@payez/next-mvp 4.0.0 → 4.0.2
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-handlers/account/change-password.js +110 -110
- package/dist/api-handlers/admin/analytics.d.ts +19 -19
- package/dist/api-handlers/admin/analytics.js +378 -378
- package/dist/api-handlers/admin/audit.d.ts +19 -19
- package/dist/api-handlers/admin/audit.js +213 -213
- package/dist/api-handlers/admin/index.d.ts +21 -21
- package/dist/api-handlers/admin/index.js +42 -42
- package/dist/api-handlers/admin/redis-sessions.d.ts +35 -35
- package/dist/api-handlers/admin/redis-sessions.js +203 -203
- package/dist/api-handlers/admin/sessions.d.ts +20 -20
- package/dist/api-handlers/admin/sessions.js +283 -283
- package/dist/api-handlers/admin/site-logs.d.ts +45 -45
- package/dist/api-handlers/admin/site-logs.js +317 -317
- package/dist/api-handlers/admin/stats.d.ts +20 -20
- package/dist/api-handlers/admin/stats.js +239 -239
- package/dist/api-handlers/admin/users.d.ts +19 -19
- package/dist/api-handlers/admin/users.js +221 -221
- package/dist/api-handlers/admin/vibe-data.d.ts +79 -79
- package/dist/api-handlers/admin/vibe-data.js +267 -267
- package/dist/api-handlers/auth/refresh.js +633 -633
- package/dist/api-handlers/auth/signout.js +186 -186
- package/dist/api-handlers/auth/verify-code.d.ts +43 -43
- package/dist/api-handlers/auth/verify-code.js +90 -90
- package/dist/api-handlers/session/viability.js +114 -114
- package/dist/api-handlers/test/force-expire.js +59 -59
- package/dist/auth/auth-decision.js +182 -182
- package/dist/auth/utils/token-utils.d.ts +83 -83
- package/dist/auth/utils/token-utils.js +218 -218
- package/dist/client/AuthContext.js +115 -115
- package/dist/client/better-auth-client.d.ts +1020 -1020
- package/dist/components/SessionSync.js +121 -121
- package/dist/components/account/MobileNavDrawer.js +64 -64
- package/dist/components/account/UserAvatarMenu.js +91 -91
- package/dist/components/admin/VibeAdminLayout.js +71 -71
- package/dist/hooks/useAuthSettings.js +93 -93
- package/dist/hooks/useAvailableProviders.d.ts +43 -43
- package/dist/hooks/useAvailableProviders.js +112 -112
- package/dist/lib/app-slug.d.ts +95 -95
- package/dist/lib/app-slug.js +172 -172
- package/dist/lib/test-aware-get-token.js +86 -86
- package/dist/lib/token-lifecycle.d.ts +78 -78
- package/dist/lib/token-lifecycle.js +360 -360
- package/dist/pages/admin-login/page.js +73 -73
- package/dist/pages/client-admin/ClientSiteAdminPage.js +179 -179
- package/dist/pages/login/page.js +202 -202
- package/dist/pages/showcase/ShowcasePage.js +142 -142
- package/dist/pages/test-env/EmergencyLogoutPage.js +99 -99
- package/dist/pages/test-env/JwtInspectPage.js +116 -116
- package/dist/pages/test-env/TestEnvPage.js +51 -51
- package/dist/pages/verify-code/page.js +412 -412
- package/dist/routes/auth/logout.d.ts +31 -31
- package/dist/routes/auth/logout.js +98 -98
- package/dist/routes/auth/session.js +157 -157
- package/dist/routes/auth/viability.js +190 -190
- package/package.json +6 -16
- package/dist/auth/auth-options.d.ts +0 -57
- package/dist/auth/auth-options.js +0 -213
- package/dist/auth/callbacks/index.d.ts +0 -6
- package/dist/auth/callbacks/index.js +0 -12
- package/dist/auth/callbacks/jwt.d.ts +0 -45
- package/dist/auth/callbacks/jwt.js +0 -305
- package/dist/auth/callbacks/session.d.ts +0 -60
- package/dist/auth/callbacks/session.js +0 -170
- package/dist/auth/callbacks/signin.d.ts +0 -23
- package/dist/auth/callbacks/signin.js +0 -44
- package/dist/auth/events/index.d.ts +0 -4
- package/dist/auth/events/index.js +0 -8
- package/dist/auth/events/signout.d.ts +0 -17
- package/dist/auth/events/signout.js +0 -32
- package/dist/auth/providers/credentials.d.ts +0 -32
- package/dist/auth/providers/credentials.js +0 -223
- package/dist/auth/providers/index.d.ts +0 -5
- package/dist/auth/providers/index.js +0 -21
- package/dist/auth/providers/oauth.d.ts +0 -26
- package/dist/auth/providers/oauth.js +0 -105
- package/dist/lib/nextauth-secret.d.ts +0 -10
- package/dist/lib/nextauth-secret.js +0 -100
- package/dist/pages/profile/profile-patch.d.ts +0 -1
- package/dist/pages/profile/profile-patch.js +0 -281
- package/dist/pages/security/security-patch.d.ts +0 -1
- package/dist/pages/security/security-patch.js +0 -302
|
@@ -1,186 +1,186 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Authentication Signout API Handler
|
|
4
|
-
*
|
|
5
|
-
* Handles user session termination and cookie cleanup.
|
|
6
|
-
* This handler is designed to be imported and used by Next.js applications
|
|
7
|
-
* using the @payez/next-mvp package.
|
|
8
|
-
*
|
|
9
|
-
* @version 2.0
|
|
10
|
-
* @requires No authentication (public endpoint)
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.POST = void 0;
|
|
14
|
-
exports.createSignoutHandler = createSignoutHandler;
|
|
15
|
-
const server_1 = require("next/server");
|
|
16
|
-
const headers_1 = require("next/headers");
|
|
17
|
-
const session_store_1 = require("../../lib/session-store");
|
|
18
|
-
const auth_1 = require("../../server/auth");
|
|
19
|
-
const app_slug_1 = require("../../lib/app-slug");
|
|
20
|
-
// JWT decode helper - simple base64 decode without verification
|
|
21
|
-
function jwtDecode(token) {
|
|
22
|
-
try {
|
|
23
|
-
const parts = token.split('.');
|
|
24
|
-
if (parts.length !== 3)
|
|
25
|
-
return null;
|
|
26
|
-
const payload = parts[1];
|
|
27
|
-
const decoded = Buffer.from(payload, 'base64').toString('utf-8');
|
|
28
|
-
return JSON.parse(decoded);
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// Add protection headers to all responses
|
|
35
|
-
function addSecurityHeaders(response) {
|
|
36
|
-
response.headers.set('Content-Security-Policy', "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self';");
|
|
37
|
-
response.headers.set('X-Frame-Options', 'DENY');
|
|
38
|
-
response.headers.set('X-Content-Type-Options', 'nosniff');
|
|
39
|
-
response.headers.set('X-XSS-Protection', '1; mode=block');
|
|
40
|
-
response.headers.set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains; preload');
|
|
41
|
-
response.headers.set('Referrer-Policy', 'strict-origin-when-cross-origin');
|
|
42
|
-
response.headers.set('Permissions-Policy', 'geolocation=(), microphone=(), camera=(), payment=(), usb=(), magnetometer=(), gyroscope=(), accelerometer=()');
|
|
43
|
-
response.headers.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
|
|
44
|
-
response.headers.set('Pragma', 'no-cache');
|
|
45
|
-
response.headers.set('Expires', '0');
|
|
46
|
-
return response;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Creates a signout handler for Next.js API routes
|
|
50
|
-
*
|
|
51
|
-
* @param config Configuration for NextAuth
|
|
52
|
-
* @returns Next.js POST handler function
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* // In your app's /app/api/auth/signout/route.ts
|
|
57
|
-
* import { createSignoutHandler } from '@payez/next-mvp/api-handlers/auth/signout';
|
|
58
|
-
*
|
|
59
|
-
* export const POST = createSignoutHandler({
|
|
60
|
-
* nextAuthSecret: process.env.NEXTAUTH_SECRET!
|
|
61
|
-
* });
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
function createSignoutHandler(config) {
|
|
65
|
-
const { nextAuthSecret } = config;
|
|
66
|
-
return async function POST(req) {
|
|
67
|
-
const cookieStore = await (0, headers_1.cookies)();
|
|
68
|
-
// Get app-slug prefixed cookie names
|
|
69
|
-
const sessionCookieName = (0, app_slug_1.getSessionCookieName)();
|
|
70
|
-
const secureSessionCookieName = (0, app_slug_1.getSecureSessionCookieName)();
|
|
71
|
-
// Handle chunked session tokens (for large JWTs)
|
|
72
|
-
let sessionToken;
|
|
73
|
-
const sessionTokenCookie = cookieStore.get(sessionCookieName);
|
|
74
|
-
if (sessionTokenCookie?.value) {
|
|
75
|
-
// Single cookie case
|
|
76
|
-
sessionToken = sessionTokenCookie.value;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
// Chunked cookie case - reconstruct from parts
|
|
80
|
-
const chunkCookies = cookieStore.getAll()
|
|
81
|
-
.filter(cookie => cookie.name.startsWith(`${sessionCookieName}.`))
|
|
82
|
-
.sort((a, b) => {
|
|
83
|
-
const aIndex = parseInt(a.name.split('.').pop() || '0');
|
|
84
|
-
const bIndex = parseInt(b.name.split('.').pop() || '0');
|
|
85
|
-
return aIndex - bIndex;
|
|
86
|
-
});
|
|
87
|
-
if (chunkCookies.length > 0) {
|
|
88
|
-
sessionToken = chunkCookies.map(cookie => cookie.value).join('');
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// Get chunk cookies for cleanup count
|
|
92
|
-
const chunkCookies = cookieStore.getAll()
|
|
93
|
-
.filter(cookie => cookie.name.startsWith(`${sessionCookieName}.`));
|
|
94
|
-
// Decode NextAuth JWT to extract the Redis session UUID before deletion
|
|
95
|
-
let redisSessionToken = null;
|
|
96
|
-
// First attempt: Better Auth getSession
|
|
97
|
-
try {
|
|
98
|
-
const betterAuthSession = await (0, auth_1.getSession)(req);
|
|
99
|
-
redisSessionToken = betterAuthSession?.session?.token || null;
|
|
100
|
-
}
|
|
101
|
-
catch (e) {
|
|
102
|
-
console.warn('[SIGNOUT] getSession() failed to extract session token (will try manual decode)');
|
|
103
|
-
}
|
|
104
|
-
// Second attempt: manual decode of the session cookie JWT (no verification)
|
|
105
|
-
if (!redisSessionToken && (sessionToken || cookieStore.getAll().some(c => c.name.startsWith(`${sessionCookieName}.`)))) {
|
|
106
|
-
try {
|
|
107
|
-
// Reconstruct raw JWT from chunked cookies if necessary
|
|
108
|
-
let rawJwt = null;
|
|
109
|
-
const direct = cookieStore.get(sessionCookieName);
|
|
110
|
-
if (direct?.value) {
|
|
111
|
-
rawJwt = direct.value;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
const chunks = cookieStore.getAll()
|
|
115
|
-
.filter(c => c.name.startsWith(`${sessionCookieName}.`))
|
|
116
|
-
.sort((a, b) => {
|
|
117
|
-
const ai = parseInt(a.name.split('.').pop() || '0');
|
|
118
|
-
const bi = parseInt(b.name.split('.').pop() || '0');
|
|
119
|
-
return ai - bi;
|
|
120
|
-
})
|
|
121
|
-
.map(c => c.value);
|
|
122
|
-
if (chunks.length > 0)
|
|
123
|
-
rawJwt = chunks.join('');
|
|
124
|
-
}
|
|
125
|
-
if (rawJwt) {
|
|
126
|
-
const decoded = jwtDecode(rawJwt);
|
|
127
|
-
if (decoded && typeof decoded === 'object' && typeof decoded.sessionToken === 'string') {
|
|
128
|
-
redisSessionToken = decoded.sessionToken;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
catch (e) {
|
|
133
|
-
console.warn('[SIGNOUT] Manual JWT decode failed to extract session token');
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
// Delete Redis session if UUID was extracted
|
|
137
|
-
if (redisSessionToken) {
|
|
138
|
-
try {
|
|
139
|
-
await (0, session_store_1.deleteSession)(redisSessionToken);
|
|
140
|
-
console.info('[SIGNOUT] Redis session cleanup successful', {
|
|
141
|
-
sessionToken: redisSessionToken.substring(0, 8) + '...'
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
catch (sessionError) {
|
|
145
|
-
// Log error but don't fail the signout process
|
|
146
|
-
console.error('[SIGNOUT] Redis session cleanup failed', { error: sessionError });
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
console.warn('[SIGNOUT] No Redis session token (UUID) extracted from cookie; skipping Redis deletion');
|
|
151
|
-
}
|
|
152
|
-
// Build response
|
|
153
|
-
const responseData = {
|
|
154
|
-
success: true,
|
|
155
|
-
message: sessionToken ? 'Session deleted successfully' : 'No active session found',
|
|
156
|
-
sessionDeleted: !!sessionToken,
|
|
157
|
-
chunkCookiesDeleted: chunkCookies.length
|
|
158
|
-
};
|
|
159
|
-
const response = server_1.NextResponse.json(responseData);
|
|
160
|
-
// Always clear cookies, regardless of success/failure (using app-slug prefixed names)
|
|
161
|
-
try {
|
|
162
|
-
response.cookies.delete(sessionCookieName);
|
|
163
|
-
response.cookies.delete(secureSessionCookieName);
|
|
164
|
-
response.cookies.delete((0, app_slug_1.getCsrfCookieName)());
|
|
165
|
-
response.cookies.delete((0, app_slug_1.getSecureCsrfCookieName)());
|
|
166
|
-
response.cookies.delete((0, app_slug_1.getCallbackUrlCookieName)());
|
|
167
|
-
response.cookies.delete(`__Secure-${(0, app_slug_1.getCallbackUrlCookieName)()}`);
|
|
168
|
-
response.cookies.delete('twoFactorSessionVerified');
|
|
169
|
-
// Delete chunked session cookies
|
|
170
|
-
chunkCookies.forEach(cookie => {
|
|
171
|
-
response.cookies.delete(cookie.name);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
catch (cookieError) {
|
|
175
|
-
console.error('[SIGNOUT] Cookie cleanup failed:', cookieError);
|
|
176
|
-
}
|
|
177
|
-
return addSecurityHeaders(response);
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Default export for backward compatibility
|
|
182
|
-
* Requires environment variable: NEXTAUTH_SECRET
|
|
183
|
-
*/
|
|
184
|
-
exports.POST = createSignoutHandler({
|
|
185
|
-
nextAuthSecret: process.env.NEXTAUTH_SECRET || ''
|
|
186
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Authentication Signout API Handler
|
|
4
|
+
*
|
|
5
|
+
* Handles user session termination and cookie cleanup.
|
|
6
|
+
* This handler is designed to be imported and used by Next.js applications
|
|
7
|
+
* using the @payez/next-mvp package.
|
|
8
|
+
*
|
|
9
|
+
* @version 2.0
|
|
10
|
+
* @requires No authentication (public endpoint)
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.POST = void 0;
|
|
14
|
+
exports.createSignoutHandler = createSignoutHandler;
|
|
15
|
+
const server_1 = require("next/server");
|
|
16
|
+
const headers_1 = require("next/headers");
|
|
17
|
+
const session_store_1 = require("../../lib/session-store");
|
|
18
|
+
const auth_1 = require("../../server/auth");
|
|
19
|
+
const app_slug_1 = require("../../lib/app-slug");
|
|
20
|
+
// JWT decode helper - simple base64 decode without verification
|
|
21
|
+
function jwtDecode(token) {
|
|
22
|
+
try {
|
|
23
|
+
const parts = token.split('.');
|
|
24
|
+
if (parts.length !== 3)
|
|
25
|
+
return null;
|
|
26
|
+
const payload = parts[1];
|
|
27
|
+
const decoded = Buffer.from(payload, 'base64').toString('utf-8');
|
|
28
|
+
return JSON.parse(decoded);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Add protection headers to all responses
|
|
35
|
+
function addSecurityHeaders(response) {
|
|
36
|
+
response.headers.set('Content-Security-Policy', "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self';");
|
|
37
|
+
response.headers.set('X-Frame-Options', 'DENY');
|
|
38
|
+
response.headers.set('X-Content-Type-Options', 'nosniff');
|
|
39
|
+
response.headers.set('X-XSS-Protection', '1; mode=block');
|
|
40
|
+
response.headers.set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains; preload');
|
|
41
|
+
response.headers.set('Referrer-Policy', 'strict-origin-when-cross-origin');
|
|
42
|
+
response.headers.set('Permissions-Policy', 'geolocation=(), microphone=(), camera=(), payment=(), usb=(), magnetometer=(), gyroscope=(), accelerometer=()');
|
|
43
|
+
response.headers.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
|
|
44
|
+
response.headers.set('Pragma', 'no-cache');
|
|
45
|
+
response.headers.set('Expires', '0');
|
|
46
|
+
return response;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Creates a signout handler for Next.js API routes
|
|
50
|
+
*
|
|
51
|
+
* @param config Configuration for NextAuth
|
|
52
|
+
* @returns Next.js POST handler function
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // In your app's /app/api/auth/signout/route.ts
|
|
57
|
+
* import { createSignoutHandler } from '@payez/next-mvp/api-handlers/auth/signout';
|
|
58
|
+
*
|
|
59
|
+
* export const POST = createSignoutHandler({
|
|
60
|
+
* nextAuthSecret: process.env.NEXTAUTH_SECRET!
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function createSignoutHandler(config) {
|
|
65
|
+
const { nextAuthSecret } = config;
|
|
66
|
+
return async function POST(req) {
|
|
67
|
+
const cookieStore = await (0, headers_1.cookies)();
|
|
68
|
+
// Get app-slug prefixed cookie names
|
|
69
|
+
const sessionCookieName = (0, app_slug_1.getSessionCookieName)();
|
|
70
|
+
const secureSessionCookieName = (0, app_slug_1.getSecureSessionCookieName)();
|
|
71
|
+
// Handle chunked session tokens (for large JWTs)
|
|
72
|
+
let sessionToken;
|
|
73
|
+
const sessionTokenCookie = cookieStore.get(sessionCookieName);
|
|
74
|
+
if (sessionTokenCookie?.value) {
|
|
75
|
+
// Single cookie case
|
|
76
|
+
sessionToken = sessionTokenCookie.value;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// Chunked cookie case - reconstruct from parts
|
|
80
|
+
const chunkCookies = cookieStore.getAll()
|
|
81
|
+
.filter(cookie => cookie.name.startsWith(`${sessionCookieName}.`))
|
|
82
|
+
.sort((a, b) => {
|
|
83
|
+
const aIndex = parseInt(a.name.split('.').pop() || '0');
|
|
84
|
+
const bIndex = parseInt(b.name.split('.').pop() || '0');
|
|
85
|
+
return aIndex - bIndex;
|
|
86
|
+
});
|
|
87
|
+
if (chunkCookies.length > 0) {
|
|
88
|
+
sessionToken = chunkCookies.map(cookie => cookie.value).join('');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Get chunk cookies for cleanup count
|
|
92
|
+
const chunkCookies = cookieStore.getAll()
|
|
93
|
+
.filter(cookie => cookie.name.startsWith(`${sessionCookieName}.`));
|
|
94
|
+
// Decode NextAuth JWT to extract the Redis session UUID before deletion
|
|
95
|
+
let redisSessionToken = null;
|
|
96
|
+
// First attempt: Better Auth getSession
|
|
97
|
+
try {
|
|
98
|
+
const betterAuthSession = await (0, auth_1.getSession)(req);
|
|
99
|
+
redisSessionToken = betterAuthSession?.session?.token || null;
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
console.warn('[SIGNOUT] getSession() failed to extract session token (will try manual decode)');
|
|
103
|
+
}
|
|
104
|
+
// Second attempt: manual decode of the session cookie JWT (no verification)
|
|
105
|
+
if (!redisSessionToken && (sessionToken || cookieStore.getAll().some(c => c.name.startsWith(`${sessionCookieName}.`)))) {
|
|
106
|
+
try {
|
|
107
|
+
// Reconstruct raw JWT from chunked cookies if necessary
|
|
108
|
+
let rawJwt = null;
|
|
109
|
+
const direct = cookieStore.get(sessionCookieName);
|
|
110
|
+
if (direct?.value) {
|
|
111
|
+
rawJwt = direct.value;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const chunks = cookieStore.getAll()
|
|
115
|
+
.filter(c => c.name.startsWith(`${sessionCookieName}.`))
|
|
116
|
+
.sort((a, b) => {
|
|
117
|
+
const ai = parseInt(a.name.split('.').pop() || '0');
|
|
118
|
+
const bi = parseInt(b.name.split('.').pop() || '0');
|
|
119
|
+
return ai - bi;
|
|
120
|
+
})
|
|
121
|
+
.map(c => c.value);
|
|
122
|
+
if (chunks.length > 0)
|
|
123
|
+
rawJwt = chunks.join('');
|
|
124
|
+
}
|
|
125
|
+
if (rawJwt) {
|
|
126
|
+
const decoded = jwtDecode(rawJwt);
|
|
127
|
+
if (decoded && typeof decoded === 'object' && typeof decoded.sessionToken === 'string') {
|
|
128
|
+
redisSessionToken = decoded.sessionToken;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
console.warn('[SIGNOUT] Manual JWT decode failed to extract session token');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Delete Redis session if UUID was extracted
|
|
137
|
+
if (redisSessionToken) {
|
|
138
|
+
try {
|
|
139
|
+
await (0, session_store_1.deleteSession)(redisSessionToken);
|
|
140
|
+
console.info('[SIGNOUT] Redis session cleanup successful', {
|
|
141
|
+
sessionToken: redisSessionToken.substring(0, 8) + '...'
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
catch (sessionError) {
|
|
145
|
+
// Log error but don't fail the signout process
|
|
146
|
+
console.error('[SIGNOUT] Redis session cleanup failed', { error: sessionError });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
console.warn('[SIGNOUT] No Redis session token (UUID) extracted from cookie; skipping Redis deletion');
|
|
151
|
+
}
|
|
152
|
+
// Build response
|
|
153
|
+
const responseData = {
|
|
154
|
+
success: true,
|
|
155
|
+
message: sessionToken ? 'Session deleted successfully' : 'No active session found',
|
|
156
|
+
sessionDeleted: !!sessionToken,
|
|
157
|
+
chunkCookiesDeleted: chunkCookies.length
|
|
158
|
+
};
|
|
159
|
+
const response = server_1.NextResponse.json(responseData);
|
|
160
|
+
// Always clear cookies, regardless of success/failure (using app-slug prefixed names)
|
|
161
|
+
try {
|
|
162
|
+
response.cookies.delete(sessionCookieName);
|
|
163
|
+
response.cookies.delete(secureSessionCookieName);
|
|
164
|
+
response.cookies.delete((0, app_slug_1.getCsrfCookieName)());
|
|
165
|
+
response.cookies.delete((0, app_slug_1.getSecureCsrfCookieName)());
|
|
166
|
+
response.cookies.delete((0, app_slug_1.getCallbackUrlCookieName)());
|
|
167
|
+
response.cookies.delete(`__Secure-${(0, app_slug_1.getCallbackUrlCookieName)()}`);
|
|
168
|
+
response.cookies.delete('twoFactorSessionVerified');
|
|
169
|
+
// Delete chunked session cookies
|
|
170
|
+
chunkCookies.forEach(cookie => {
|
|
171
|
+
response.cookies.delete(cookie.name);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
catch (cookieError) {
|
|
175
|
+
console.error('[SIGNOUT] Cookie cleanup failed:', cookieError);
|
|
176
|
+
}
|
|
177
|
+
return addSecurityHeaders(response);
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Default export for backward compatibility
|
|
182
|
+
* Requires environment variable: NEXTAUTH_SECRET
|
|
183
|
+
*/
|
|
184
|
+
exports.POST = createSignoutHandler({
|
|
185
|
+
nextAuthSecret: process.env.NEXTAUTH_SECRET || ''
|
|
186
|
+
});
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authentication Verify Code / Complete 2FA API Handler
|
|
3
|
-
*
|
|
4
|
-
* Handles 2FA verification and token updates after successful verification.
|
|
5
|
-
* This handler is designed to be imported and used by Next.js applications
|
|
6
|
-
* using the @payez/next-mvp package.
|
|
7
|
-
*
|
|
8
|
-
* @version 2.0
|
|
9
|
-
* @requires Authentication (authenticated endpoint)
|
|
10
|
-
*/
|
|
11
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
12
|
-
interface VerifyCodeConfig {
|
|
13
|
-
nextAuthSecret?: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Creates a verify-code/complete-2FA handler for Next.js API routes
|
|
17
|
-
*
|
|
18
|
-
* @param config Configuration for NextAuth
|
|
19
|
-
* @returns Next.js POST handler function
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* // In your app's /app/api/auth/verify-code/route.ts
|
|
24
|
-
* import { createVerifyCodeHandler } from '@payez/next-mvp/api-handlers/auth/verify-code';
|
|
25
|
-
*
|
|
26
|
-
* export const POST = createVerifyCodeHandler({
|
|
27
|
-
* nextAuthSecret: process.env.NEXTAUTH_SECRET!
|
|
28
|
-
* });
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export declare function createVerifyCodeHandler(config: VerifyCodeConfig): (req: NextRequest) => Promise<NextResponse<{
|
|
32
|
-
success: boolean;
|
|
33
|
-
message: string;
|
|
34
|
-
}>>;
|
|
35
|
-
/**
|
|
36
|
-
* Default export for backward compatibility
|
|
37
|
-
* Requires environment variable: NEXTAUTH_SECRET
|
|
38
|
-
*/
|
|
39
|
-
export declare const POST: (req: NextRequest) => Promise<NextResponse<{
|
|
40
|
-
success: boolean;
|
|
41
|
-
message: string;
|
|
42
|
-
}>>;
|
|
43
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Verify Code / Complete 2FA API Handler
|
|
3
|
+
*
|
|
4
|
+
* Handles 2FA verification and token updates after successful verification.
|
|
5
|
+
* This handler is designed to be imported and used by Next.js applications
|
|
6
|
+
* using the @payez/next-mvp package.
|
|
7
|
+
*
|
|
8
|
+
* @version 2.0
|
|
9
|
+
* @requires Authentication (authenticated endpoint)
|
|
10
|
+
*/
|
|
11
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
12
|
+
interface VerifyCodeConfig {
|
|
13
|
+
nextAuthSecret?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a verify-code/complete-2FA handler for Next.js API routes
|
|
17
|
+
*
|
|
18
|
+
* @param config Configuration for NextAuth
|
|
19
|
+
* @returns Next.js POST handler function
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // In your app's /app/api/auth/verify-code/route.ts
|
|
24
|
+
* import { createVerifyCodeHandler } from '@payez/next-mvp/api-handlers/auth/verify-code';
|
|
25
|
+
*
|
|
26
|
+
* export const POST = createVerifyCodeHandler({
|
|
27
|
+
* nextAuthSecret: process.env.NEXTAUTH_SECRET!
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function createVerifyCodeHandler(config: VerifyCodeConfig): (req: NextRequest) => Promise<NextResponse<{
|
|
32
|
+
success: boolean;
|
|
33
|
+
message: string;
|
|
34
|
+
}>>;
|
|
35
|
+
/**
|
|
36
|
+
* Default export for backward compatibility
|
|
37
|
+
* Requires environment variable: NEXTAUTH_SECRET
|
|
38
|
+
*/
|
|
39
|
+
export declare const POST: (req: NextRequest) => Promise<NextResponse<{
|
|
40
|
+
success: boolean;
|
|
41
|
+
message: string;
|
|
42
|
+
}>>;
|
|
43
|
+
export {};
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Authentication Verify Code / Complete 2FA API Handler
|
|
4
|
-
*
|
|
5
|
-
* Handles 2FA verification and token updates after successful verification.
|
|
6
|
-
* This handler is designed to be imported and used by Next.js applications
|
|
7
|
-
* using the @payez/next-mvp package.
|
|
8
|
-
*
|
|
9
|
-
* @version 2.0
|
|
10
|
-
* @requires Authentication (authenticated endpoint)
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.POST = void 0;
|
|
14
|
-
exports.createVerifyCodeHandler = createVerifyCodeHandler;
|
|
15
|
-
const server_1 = require("next/server");
|
|
16
|
-
const auth_1 = require("../../server/auth");
|
|
17
|
-
const session_store_1 = require("../../lib/session-store");
|
|
18
|
-
/**
|
|
19
|
-
* Creates a verify-code/complete-2FA handler for Next.js API routes
|
|
20
|
-
*
|
|
21
|
-
* @param config Configuration for NextAuth
|
|
22
|
-
* @returns Next.js POST handler function
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* // In your app's /app/api/auth/verify-code/route.ts
|
|
27
|
-
* import { createVerifyCodeHandler } from '@payez/next-mvp/api-handlers/auth/verify-code';
|
|
28
|
-
*
|
|
29
|
-
* export const POST = createVerifyCodeHandler({
|
|
30
|
-
* nextAuthSecret: process.env.NEXTAUTH_SECRET!
|
|
31
|
-
* });
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
function createVerifyCodeHandler(config) {
|
|
35
|
-
const { nextAuthSecret } = config;
|
|
36
|
-
return async function POST(req) {
|
|
37
|
-
try {
|
|
38
|
-
let body;
|
|
39
|
-
try {
|
|
40
|
-
body = await req.json();
|
|
41
|
-
}
|
|
42
|
-
catch (parseError) {
|
|
43
|
-
return server_1.NextResponse.json({ success: false, message: 'Invalid JSON format' }, { status: 400 });
|
|
44
|
-
}
|
|
45
|
-
const { accessToken, refreshToken, accessTokenExpires, refreshTokenExpires } = body;
|
|
46
|
-
// Get current session from Better Auth
|
|
47
|
-
const betterAuthSession = await (0, auth_1.getSession)(req);
|
|
48
|
-
const sessionToken = betterAuthSession?.session?.token;
|
|
49
|
-
if (!sessionToken) {
|
|
50
|
-
console.error('[VERIFY-CODE] No session token found', {
|
|
51
|
-
hasSession: !!betterAuthSession,
|
|
52
|
-
});
|
|
53
|
-
return server_1.NextResponse.json({ success: false, message: 'No session found' }, { status: 401 });
|
|
54
|
-
}
|
|
55
|
-
console.info('[VERIFY-CODE] Updating session with new tokens after 2FA', {
|
|
56
|
-
sessionToken: sessionToken.substring(0, 8) + '...',
|
|
57
|
-
userId: betterAuthSession?.user?.id,
|
|
58
|
-
hasAccessToken: !!accessToken,
|
|
59
|
-
hasRefreshToken: !!refreshToken,
|
|
60
|
-
accessTokenLength: accessToken?.length,
|
|
61
|
-
refreshTokenLength: refreshToken?.length
|
|
62
|
-
});
|
|
63
|
-
// Update tokens in Redis
|
|
64
|
-
await (0, session_store_1.updateTokens)(sessionToken, accessToken, refreshToken, accessTokenExpires, refreshTokenExpires);
|
|
65
|
-
// Mark 2FA as complete
|
|
66
|
-
await (0, session_store_1.mark2FAComplete)(sessionToken);
|
|
67
|
-
console.info('[VERIFY-CODE] 2FA completion successful', {
|
|
68
|
-
sessionToken: sessionToken.substring(0, 8) + '...',
|
|
69
|
-
userId: betterAuthSession?.user?.id
|
|
70
|
-
});
|
|
71
|
-
return server_1.NextResponse.json({
|
|
72
|
-
success: true,
|
|
73
|
-
message: '2FA verification complete'
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
console.error('[VERIFY-CODE] Failed to complete 2FA', {
|
|
78
|
-
error: error instanceof Error ? error.message : String(error)
|
|
79
|
-
});
|
|
80
|
-
return server_1.NextResponse.json({ success: false, message: 'Failed to complete 2FA' }, { status: 500 });
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Default export for backward compatibility
|
|
86
|
-
* Requires environment variable: NEXTAUTH_SECRET
|
|
87
|
-
*/
|
|
88
|
-
exports.POST = createVerifyCodeHandler({
|
|
89
|
-
nextAuthSecret: process.env.NEXTAUTH_SECRET || ''
|
|
90
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Authentication Verify Code / Complete 2FA API Handler
|
|
4
|
+
*
|
|
5
|
+
* Handles 2FA verification and token updates after successful verification.
|
|
6
|
+
* This handler is designed to be imported and used by Next.js applications
|
|
7
|
+
* using the @payez/next-mvp package.
|
|
8
|
+
*
|
|
9
|
+
* @version 2.0
|
|
10
|
+
* @requires Authentication (authenticated endpoint)
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.POST = void 0;
|
|
14
|
+
exports.createVerifyCodeHandler = createVerifyCodeHandler;
|
|
15
|
+
const server_1 = require("next/server");
|
|
16
|
+
const auth_1 = require("../../server/auth");
|
|
17
|
+
const session_store_1 = require("../../lib/session-store");
|
|
18
|
+
/**
|
|
19
|
+
* Creates a verify-code/complete-2FA handler for Next.js API routes
|
|
20
|
+
*
|
|
21
|
+
* @param config Configuration for NextAuth
|
|
22
|
+
* @returns Next.js POST handler function
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // In your app's /app/api/auth/verify-code/route.ts
|
|
27
|
+
* import { createVerifyCodeHandler } from '@payez/next-mvp/api-handlers/auth/verify-code';
|
|
28
|
+
*
|
|
29
|
+
* export const POST = createVerifyCodeHandler({
|
|
30
|
+
* nextAuthSecret: process.env.NEXTAUTH_SECRET!
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function createVerifyCodeHandler(config) {
|
|
35
|
+
const { nextAuthSecret } = config;
|
|
36
|
+
return async function POST(req) {
|
|
37
|
+
try {
|
|
38
|
+
let body;
|
|
39
|
+
try {
|
|
40
|
+
body = await req.json();
|
|
41
|
+
}
|
|
42
|
+
catch (parseError) {
|
|
43
|
+
return server_1.NextResponse.json({ success: false, message: 'Invalid JSON format' }, { status: 400 });
|
|
44
|
+
}
|
|
45
|
+
const { accessToken, refreshToken, accessTokenExpires, refreshTokenExpires } = body;
|
|
46
|
+
// Get current session from Better Auth
|
|
47
|
+
const betterAuthSession = await (0, auth_1.getSession)(req);
|
|
48
|
+
const sessionToken = betterAuthSession?.session?.token;
|
|
49
|
+
if (!sessionToken) {
|
|
50
|
+
console.error('[VERIFY-CODE] No session token found', {
|
|
51
|
+
hasSession: !!betterAuthSession,
|
|
52
|
+
});
|
|
53
|
+
return server_1.NextResponse.json({ success: false, message: 'No session found' }, { status: 401 });
|
|
54
|
+
}
|
|
55
|
+
console.info('[VERIFY-CODE] Updating session with new tokens after 2FA', {
|
|
56
|
+
sessionToken: sessionToken.substring(0, 8) + '...',
|
|
57
|
+
userId: betterAuthSession?.user?.id,
|
|
58
|
+
hasAccessToken: !!accessToken,
|
|
59
|
+
hasRefreshToken: !!refreshToken,
|
|
60
|
+
accessTokenLength: accessToken?.length,
|
|
61
|
+
refreshTokenLength: refreshToken?.length
|
|
62
|
+
});
|
|
63
|
+
// Update tokens in Redis
|
|
64
|
+
await (0, session_store_1.updateTokens)(sessionToken, accessToken, refreshToken, accessTokenExpires, refreshTokenExpires);
|
|
65
|
+
// Mark 2FA as complete
|
|
66
|
+
await (0, session_store_1.mark2FAComplete)(sessionToken);
|
|
67
|
+
console.info('[VERIFY-CODE] 2FA completion successful', {
|
|
68
|
+
sessionToken: sessionToken.substring(0, 8) + '...',
|
|
69
|
+
userId: betterAuthSession?.user?.id
|
|
70
|
+
});
|
|
71
|
+
return server_1.NextResponse.json({
|
|
72
|
+
success: true,
|
|
73
|
+
message: '2FA verification complete'
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error('[VERIFY-CODE] Failed to complete 2FA', {
|
|
78
|
+
error: error instanceof Error ? error.message : String(error)
|
|
79
|
+
});
|
|
80
|
+
return server_1.NextResponse.json({ success: false, message: 'Failed to complete 2FA' }, { status: 500 });
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Default export for backward compatibility
|
|
86
|
+
* Requires environment variable: NEXTAUTH_SECRET
|
|
87
|
+
*/
|
|
88
|
+
exports.POST = createVerifyCodeHandler({
|
|
89
|
+
nextAuthSecret: process.env.NEXTAUTH_SECRET || ''
|
|
90
|
+
});
|