@payez/next-mvp 4.8.8 → 4.8.9
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.
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
* @since auth-ready-v2
|
|
15
15
|
*/
|
|
16
16
|
import { NextRequest, NextResponse } from 'next/server';
|
|
17
|
+
/** 4.8.9: answered (status 500) when the server-side session delete failed. The browser's cookies are cleared either way. */
|
|
18
|
+
export declare const SESSION_NOT_ENDED_CODE = "SESSION_NOT_ENDED";
|
|
19
|
+
export declare const SESSION_NOT_ENDED_MESSAGE = "You were signed out on this device, but we could not end your session on the server. Try signing out again.";
|
|
17
20
|
/**
|
|
18
21
|
* POST /api/auth/logout - Sign out and clean up session
|
|
19
22
|
*
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* @since auth-ready-v2
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.SESSION_NOT_ENDED_MESSAGE = exports.SESSION_NOT_ENDED_CODE = void 0;
|
|
18
19
|
exports.POST = POST;
|
|
19
20
|
const server_1 = require("next/server");
|
|
20
21
|
const auth_1 = require("../../server/auth");
|
|
@@ -22,6 +23,9 @@ const session_store_1 = require("../../lib/session-store");
|
|
|
22
23
|
const app_slug_1 = require("../../lib/app-slug");
|
|
23
24
|
const site_logger_1 = require("../../lib/site-logger");
|
|
24
25
|
const safe_error_response_1 = require("../../lib/safe-error-response");
|
|
26
|
+
/** 4.8.9: answered (status 500) when the server-side session delete failed. The browser's cookies are cleared either way. */
|
|
27
|
+
exports.SESSION_NOT_ENDED_CODE = 'SESSION_NOT_ENDED';
|
|
28
|
+
exports.SESSION_NOT_ENDED_MESSAGE = 'You were signed out on this device, but we could not end your session on the server. Try signing out again.';
|
|
25
29
|
/**
|
|
26
30
|
* POST /api/auth/logout - Sign out and clean up session
|
|
27
31
|
*
|
|
@@ -41,6 +45,9 @@ async function POST(req) {
|
|
|
41
45
|
});
|
|
42
46
|
}
|
|
43
47
|
const sessionId = session.session?.token;
|
|
48
|
+
// 4.8.9: a sign-out that did not end the session must not say it did. The delete below can fail (a faulting store); the
|
|
49
|
+
// cookies are still cleared, but the answer is then a typed failure instead of success:true.
|
|
50
|
+
let serverDeleteFailed = false;
|
|
44
51
|
// Delete session from EVERY store — canonical + BA secondary (181922).
|
|
45
52
|
// Canonical-only deletion let the ba: record resurrect the session.
|
|
46
53
|
if (sessionId) {
|
|
@@ -49,7 +56,8 @@ async function POST(req) {
|
|
|
49
56
|
console.info('[LOGOUT_ROUTE] Session deleted from store');
|
|
50
57
|
}
|
|
51
58
|
catch (error) {
|
|
52
|
-
|
|
59
|
+
serverDeleteFailed = true;
|
|
60
|
+
console.error('[LOGOUT_ROUTE] Failed to delete session - the server session is STILL LIVE:', error);
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
// Log logout event (fire-and-forget)
|
|
@@ -65,10 +73,12 @@ async function POST(req) {
|
|
|
65
73
|
});
|
|
66
74
|
}
|
|
67
75
|
// Build response that clears session cookies
|
|
68
|
-
const response =
|
|
69
|
-
success:
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
const response = serverDeleteFailed
|
|
77
|
+
? server_1.NextResponse.json({ success: false, code: exports.SESSION_NOT_ENDED_CODE, message: exports.SESSION_NOT_ENDED_MESSAGE }, { status: 500 })
|
|
78
|
+
: server_1.NextResponse.json({
|
|
79
|
+
success: true,
|
|
80
|
+
message: 'Logged out successfully'
|
|
81
|
+
});
|
|
72
82
|
// Clear NextAuth session cookies (using app-slug prefixed names)
|
|
73
83
|
const cookieNames = [
|
|
74
84
|
(0, app_slug_1.getSessionCookieName)(),
|
package/package.json
CHANGED
|
@@ -27,6 +27,10 @@ import {
|
|
|
27
27
|
import { siteEvents, getClientIp } from '../../lib/site-logger';
|
|
28
28
|
import { logExceptionWithCorrelation } from '../../lib/safe-error-response';
|
|
29
29
|
|
|
30
|
+
/** 4.8.9: answered (status 500) when the server-side session delete failed. The browser's cookies are cleared either way. */
|
|
31
|
+
export const SESSION_NOT_ENDED_CODE = 'SESSION_NOT_ENDED';
|
|
32
|
+
export const SESSION_NOT_ENDED_MESSAGE = 'You were signed out on this device, but we could not end your session on the server. Try signing out again.';
|
|
33
|
+
|
|
30
34
|
/**
|
|
31
35
|
* POST /api/auth/logout - Sign out and clean up session
|
|
32
36
|
*
|
|
@@ -48,6 +52,9 @@ export async function POST(req: NextRequest) {
|
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
const sessionId = session.session?.token;
|
|
55
|
+
// 4.8.9: a sign-out that did not end the session must not say it did. The delete below can fail (a faulting store); the
|
|
56
|
+
// cookies are still cleared, but the answer is then a typed failure instead of success:true.
|
|
57
|
+
let serverDeleteFailed = false;
|
|
51
58
|
|
|
52
59
|
// Delete session from EVERY store — canonical + BA secondary (181922).
|
|
53
60
|
// Canonical-only deletion let the ba: record resurrect the session.
|
|
@@ -56,7 +63,8 @@ export async function POST(req: NextRequest) {
|
|
|
56
63
|
await deleteSessionEverywhere(sessionId);
|
|
57
64
|
console.info('[LOGOUT_ROUTE] Session deleted from store');
|
|
58
65
|
} catch (error) {
|
|
59
|
-
|
|
66
|
+
serverDeleteFailed = true;
|
|
67
|
+
console.error('[LOGOUT_ROUTE] Failed to delete session - the server session is STILL LIVE:', error);
|
|
60
68
|
}
|
|
61
69
|
}
|
|
62
70
|
|
|
@@ -74,10 +82,12 @@ export async function POST(req: NextRequest) {
|
|
|
74
82
|
}
|
|
75
83
|
|
|
76
84
|
// Build response that clears session cookies
|
|
77
|
-
const response =
|
|
78
|
-
success:
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
const response = serverDeleteFailed
|
|
86
|
+
? NextResponse.json({ success: false, code: SESSION_NOT_ENDED_CODE, message: SESSION_NOT_ENDED_MESSAGE }, { status: 500 })
|
|
87
|
+
: NextResponse.json({
|
|
88
|
+
success: true,
|
|
89
|
+
message: 'Logged out successfully'
|
|
90
|
+
});
|
|
81
91
|
|
|
82
92
|
// Clear NextAuth session cookies (using app-slug prefixed names)
|
|
83
93
|
const cookieNames = [
|