@infuro/cms-core 1.0.51 → 1.0.52
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/admin.cjs +1 -1
- package/dist/admin.js +1 -1
- package/dist/api.cjs +34 -34
- package/dist/api.js +3 -3
- package/dist/auth.cjs +44 -43
- package/dist/auth.d.cts +2 -3
- package/dist/auth.d.ts +2 -3
- package/dist/auth.js +2 -1
- package/dist/chunk-7L6KWI7S.cjs +212 -0
- package/dist/{chunk-YV5PK4JW.cjs → chunk-BC22I7C7.cjs} +45 -247
- package/dist/{chunk-WRKV6MHB.js → chunk-BNKZNLEX.js} +2 -196
- package/dist/chunk-WUQAOTHA.js +203 -0
- package/dist/index.cjs +267 -266
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +7 -6
- package/dist/middleware.cjs +15 -0
- package/dist/middleware.js +2 -0
- package/dist/order-notification-dispatcher-AT4IFAGL.js +1 -1
- package/dist/order-notification-dispatcher-YBAWDOIO.cjs +1 -1
- package/package.json +6 -1
- package/dist/{chunk-YOW457RA.cjs → chunk-3BPD5NGU.cjs} +2 -2
- package/dist/{chunk-NUXR7BUG.js → chunk-UO5Q5RXB.js} +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { linkUnclaimedContactToUser, ensureCustomerForUser } from './chunk-RK5ETF2I.js';
|
|
2
2
|
import { retireSoftDeletedUniqueValue } from './chunk-DBPSJYLZ.js';
|
|
3
3
|
import { getPermissionableEntityKeys, ADMIN_GROUP_NAME, isSuperAdmin, permissionRowsToRecord, vendorPortalFlagsFromUser } from './chunk-JIWUVQ6B.js';
|
|
4
|
+
import { logAuth, nextAuthCookieDebugInfo, summarizeSessionUserForLog } from './chunk-WUQAOTHA.js';
|
|
4
5
|
import { __name } from './chunk-SHUYVCID.js';
|
|
5
|
-
import { getToken } from 'next-auth/jwt';
|
|
6
6
|
import _CredentialsProvider from 'next-auth/providers/credentials';
|
|
7
7
|
import _GoogleProvider from 'next-auth/providers/google';
|
|
8
8
|
|
|
@@ -48,200 +48,6 @@ async function seedAdministratorPermissions(dataSource, entityMap) {
|
|
|
48
48
|
}
|
|
49
49
|
__name(seedAdministratorPermissions, "seedAdministratorPermissions");
|
|
50
50
|
|
|
51
|
-
// src/auth/auth-debug.ts
|
|
52
|
-
var LOG_PREFIX = "[cms-auth]";
|
|
53
|
-
function isAuthDebugEnabled() {
|
|
54
|
-
const v = process.env.CMS_AUTH_DEBUG?.trim().toLowerCase();
|
|
55
|
-
return v === "1" || v === "true" || v === "yes";
|
|
56
|
-
}
|
|
57
|
-
__name(isAuthDebugEnabled, "isAuthDebugEnabled");
|
|
58
|
-
function isAuthDebugClientEnabled() {
|
|
59
|
-
if (typeof window === "undefined") return false;
|
|
60
|
-
const v = process.env.NEXT_PUBLIC_CMS_AUTH_DEBUG?.trim().toLowerCase();
|
|
61
|
-
return v === "1" || v === "true" || v === "yes";
|
|
62
|
-
}
|
|
63
|
-
__name(isAuthDebugClientEnabled, "isAuthDebugClientEnabled");
|
|
64
|
-
function logAuth(message, data) {
|
|
65
|
-
if (!isAuthDebugEnabled()) return;
|
|
66
|
-
if (data) console.info(LOG_PREFIX, message, data);
|
|
67
|
-
else console.info(LOG_PREFIX, message);
|
|
68
|
-
}
|
|
69
|
-
__name(logAuth, "logAuth");
|
|
70
|
-
function logAuthClient(message, data) {
|
|
71
|
-
if (!isAuthDebugClientEnabled()) return;
|
|
72
|
-
if (data) console.info(LOG_PREFIX, message, data);
|
|
73
|
-
else console.info(LOG_PREFIX, message);
|
|
74
|
-
}
|
|
75
|
-
__name(logAuthClient, "logAuthClient");
|
|
76
|
-
function summarizeSessionUserForLog(user) {
|
|
77
|
-
if (!user || typeof user !== "object") return {
|
|
78
|
-
present: false
|
|
79
|
-
};
|
|
80
|
-
const u = user;
|
|
81
|
-
return {
|
|
82
|
-
present: true,
|
|
83
|
-
email: u.email ?? null,
|
|
84
|
-
id: u.id ?? null,
|
|
85
|
-
adminAccess: u.adminAccess ?? null,
|
|
86
|
-
isRBACAdmin: u.isRBACAdmin ?? null,
|
|
87
|
-
isVendorPortal: u.isVendorPortal ?? null,
|
|
88
|
-
groupName: u.groupName ?? null
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
__name(summarizeSessionUserForLog, "summarizeSessionUserForLog");
|
|
92
|
-
function nextAuthCookieDebugInfo() {
|
|
93
|
-
const nextAuthUrl = process.env.NEXTAUTH_URL ?? "(unset)";
|
|
94
|
-
const isHttps = nextAuthUrl.startsWith("https");
|
|
95
|
-
return {
|
|
96
|
-
nextAuthUrl,
|
|
97
|
-
hasSecret: Boolean(process.env.NEXTAUTH_SECRET),
|
|
98
|
-
cookieName: isHttps ? "__Secure-next-auth.session-token" : "next-auth.session-token",
|
|
99
|
-
cookieSecure: isHttps,
|
|
100
|
-
nodeEnv: process.env.NODE_ENV ?? "(unset)"
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
__name(nextAuthCookieDebugInfo, "nextAuthCookieDebugInfo");
|
|
104
|
-
|
|
105
|
-
// src/auth/middleware.ts
|
|
106
|
-
var defaultPublicApiMethods = {
|
|
107
|
-
"/api/contacts": [
|
|
108
|
-
"POST"
|
|
109
|
-
],
|
|
110
|
-
"/api/form-submissions": [
|
|
111
|
-
"POST"
|
|
112
|
-
],
|
|
113
|
-
"/api/blogs": [
|
|
114
|
-
"GET"
|
|
115
|
-
],
|
|
116
|
-
"/api/forms": [
|
|
117
|
-
"GET"
|
|
118
|
-
],
|
|
119
|
-
"/api/auth": [
|
|
120
|
-
"GET",
|
|
121
|
-
"POST"
|
|
122
|
-
],
|
|
123
|
-
"/api/health": [
|
|
124
|
-
"GET"
|
|
125
|
-
],
|
|
126
|
-
"/api/users/forgot-password": [
|
|
127
|
-
"POST"
|
|
128
|
-
],
|
|
129
|
-
"/api/users/set-password": [
|
|
130
|
-
"POST"
|
|
131
|
-
],
|
|
132
|
-
"/api/users/invite": [
|
|
133
|
-
"GET",
|
|
134
|
-
"POST"
|
|
135
|
-
],
|
|
136
|
-
/** Public keys only (e.g. googleEnabled); secrets stay private in the settings handler. */
|
|
137
|
-
"/api/settings/auth_providers": [
|
|
138
|
-
"GET"
|
|
139
|
-
]
|
|
140
|
-
};
|
|
141
|
-
function legacyGetSessionToken(request) {
|
|
142
|
-
const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
|
|
143
|
-
const regular = request.cookies.get("next-auth.session-token")?.value;
|
|
144
|
-
return secure ?? regular;
|
|
145
|
-
}
|
|
146
|
-
__name(legacyGetSessionToken, "legacyGetSessionToken");
|
|
147
|
-
function sessionCookiePresence(request) {
|
|
148
|
-
const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
|
|
149
|
-
const regular = request.cookies.get("next-auth.session-token")?.value;
|
|
150
|
-
const hasChunked = Boolean(request.cookies.get("next-auth.session-token.0")?.value) || Boolean(request.cookies.get("__Secure-next-auth.session-token.0")?.value);
|
|
151
|
-
return {
|
|
152
|
-
hasSecureToken: Boolean(secure),
|
|
153
|
-
hasRegularToken: Boolean(regular),
|
|
154
|
-
hasChunkedToken: hasChunked,
|
|
155
|
-
resolved: Boolean(secure ?? regular)
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
__name(sessionCookiePresence, "sessionCookiePresence");
|
|
159
|
-
function isPublicMethod(pathname, method, publicApiMethods) {
|
|
160
|
-
for (const [endpoint, methods] of Object.entries(publicApiMethods)) {
|
|
161
|
-
if (pathname.startsWith(endpoint) && methods.includes(method)) return true;
|
|
162
|
-
}
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
__name(isPublicMethod, "isPublicMethod");
|
|
166
|
-
async function hasValidSession(request, secret, legacyGetToken) {
|
|
167
|
-
if (request.req) {
|
|
168
|
-
const token = await getToken({
|
|
169
|
-
req: request.req,
|
|
170
|
-
secret
|
|
171
|
-
});
|
|
172
|
-
return token != null;
|
|
173
|
-
}
|
|
174
|
-
return Boolean(legacyGetToken(request));
|
|
175
|
-
}
|
|
176
|
-
__name(hasValidSession, "hasValidSession");
|
|
177
|
-
function createCmsMiddleware(config = {}) {
|
|
178
|
-
const { publicAdminPaths = [
|
|
179
|
-
"/admin/signin",
|
|
180
|
-
"/admin/forgot-password",
|
|
181
|
-
"/admin/reset-password",
|
|
182
|
-
"/admin/invite"
|
|
183
|
-
], publicApiMethods = defaultPublicApiMethods, signInPath = "/admin/signin", getSessionToken = legacyGetSessionToken, secret = process.env.NEXTAUTH_SECRET } = config;
|
|
184
|
-
return /* @__PURE__ */ __name(async function cmsMiddleware(request) {
|
|
185
|
-
const pathname = request.nextUrl.pathname;
|
|
186
|
-
const method = request.method;
|
|
187
|
-
if (publicAdminPaths.some((p) => pathname === p || pathname.startsWith(p + "/"))) {
|
|
188
|
-
return {
|
|
189
|
-
type: "next"
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
if (pathname.startsWith("/admin")) {
|
|
193
|
-
const authenticated = await hasValidSession(request, secret, getSessionToken);
|
|
194
|
-
const cookies = sessionCookiePresence(request);
|
|
195
|
-
if (!authenticated) {
|
|
196
|
-
logAuth("middleware: admin redirect to signin (no session)", {
|
|
197
|
-
pathname,
|
|
198
|
-
method,
|
|
199
|
-
usesGetToken: Boolean(request.req),
|
|
200
|
-
...cookies,
|
|
201
|
-
expectedCookieName: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token"
|
|
202
|
-
});
|
|
203
|
-
return {
|
|
204
|
-
type: "redirect",
|
|
205
|
-
url: new URL(signInPath, request.url).toString()
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
logAuth("middleware: admin allowed", {
|
|
209
|
-
pathname,
|
|
210
|
-
method,
|
|
211
|
-
usesGetToken: Boolean(request.req),
|
|
212
|
-
...cookies
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
if (pathname.startsWith("/api")) {
|
|
216
|
-
if (isPublicMethod(pathname, method, publicApiMethods)) {
|
|
217
|
-
return {
|
|
218
|
-
type: "next"
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
const authenticated = await hasValidSession(request, secret, getSessionToken);
|
|
222
|
-
if (!authenticated) {
|
|
223
|
-
logAuth("middleware: api 401 (no session)", {
|
|
224
|
-
pathname,
|
|
225
|
-
method,
|
|
226
|
-
usesGetToken: Boolean(request.req),
|
|
227
|
-
...sessionCookiePresence(request)
|
|
228
|
-
});
|
|
229
|
-
return {
|
|
230
|
-
type: "json",
|
|
231
|
-
status: 401,
|
|
232
|
-
body: {
|
|
233
|
-
error: "Unauthorized"
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return {
|
|
239
|
-
type: "next"
|
|
240
|
-
};
|
|
241
|
-
}, "cmsMiddleware");
|
|
242
|
-
}
|
|
243
|
-
__name(createCmsMiddleware, "createCmsMiddleware");
|
|
244
|
-
|
|
245
51
|
// src/auth/auth-providers-settings.ts
|
|
246
52
|
var AUTH_PROVIDERS_SETTINGS_GROUP = "auth_providers";
|
|
247
53
|
function parseEnabled(raw) {
|
|
@@ -1022,4 +828,4 @@ async function buildStorefrontNextAuthOptions(config) {
|
|
|
1022
828
|
}
|
|
1023
829
|
__name(buildStorefrontNextAuthOptions, "buildStorefrontNextAuthOptions");
|
|
1024
830
|
|
|
1025
|
-
export { AUTH_PROVIDERS_SETTINGS_GROUP, buildNextAuthOptions, buildStorefrontNextAuthOptions,
|
|
831
|
+
export { AUTH_PROVIDERS_SETTINGS_GROUP, buildNextAuthOptions, buildStorefrontNextAuthOptions, createCustomerUserFromGoogleOAuth, getNextAuthOptions, getStorefrontNextAuthOptions, googleOAuthRedirectUri, isGoogleAuthPubliclyEnabled, resolveGoogleAuthConfig, seedAdministratorPermissions };
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
// src/auth/auth-debug.ts
|
|
4
|
+
var LOG_PREFIX = "[cms-auth]";
|
|
5
|
+
function isAuthDebugEnabled() {
|
|
6
|
+
const v = process.env.CMS_AUTH_DEBUG?.trim().toLowerCase();
|
|
7
|
+
return v === "1" || v === "true" || v === "yes";
|
|
8
|
+
}
|
|
9
|
+
__name(isAuthDebugEnabled, "isAuthDebugEnabled");
|
|
10
|
+
function isAuthDebugClientEnabled() {
|
|
11
|
+
if (typeof window === "undefined") return false;
|
|
12
|
+
const v = process.env.NEXT_PUBLIC_CMS_AUTH_DEBUG?.trim().toLowerCase();
|
|
13
|
+
return v === "1" || v === "true" || v === "yes";
|
|
14
|
+
}
|
|
15
|
+
__name(isAuthDebugClientEnabled, "isAuthDebugClientEnabled");
|
|
16
|
+
function logAuth(message, data) {
|
|
17
|
+
if (!isAuthDebugEnabled()) return;
|
|
18
|
+
if (data) console.info(LOG_PREFIX, message, data);
|
|
19
|
+
else console.info(LOG_PREFIX, message);
|
|
20
|
+
}
|
|
21
|
+
__name(logAuth, "logAuth");
|
|
22
|
+
function logAuthClient(message, data) {
|
|
23
|
+
if (!isAuthDebugClientEnabled()) return;
|
|
24
|
+
if (data) console.info(LOG_PREFIX, message, data);
|
|
25
|
+
else console.info(LOG_PREFIX, message);
|
|
26
|
+
}
|
|
27
|
+
__name(logAuthClient, "logAuthClient");
|
|
28
|
+
function summarizeSessionUserForLog(user) {
|
|
29
|
+
if (!user || typeof user !== "object") return {
|
|
30
|
+
present: false
|
|
31
|
+
};
|
|
32
|
+
const u = user;
|
|
33
|
+
return {
|
|
34
|
+
present: true,
|
|
35
|
+
email: u.email ?? null,
|
|
36
|
+
id: u.id ?? null,
|
|
37
|
+
adminAccess: u.adminAccess ?? null,
|
|
38
|
+
isRBACAdmin: u.isRBACAdmin ?? null,
|
|
39
|
+
isVendorPortal: u.isVendorPortal ?? null,
|
|
40
|
+
groupName: u.groupName ?? null
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
__name(summarizeSessionUserForLog, "summarizeSessionUserForLog");
|
|
44
|
+
function nextAuthCookieDebugInfo() {
|
|
45
|
+
const nextAuthUrl = process.env.NEXTAUTH_URL ?? "(unset)";
|
|
46
|
+
const isHttps = nextAuthUrl.startsWith("https");
|
|
47
|
+
return {
|
|
48
|
+
nextAuthUrl,
|
|
49
|
+
hasSecret: Boolean(process.env.NEXTAUTH_SECRET),
|
|
50
|
+
cookieName: isHttps ? "__Secure-next-auth.session-token" : "next-auth.session-token",
|
|
51
|
+
cookieSecure: isHttps,
|
|
52
|
+
nodeEnv: process.env.NODE_ENV ?? "(unset)"
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
__name(nextAuthCookieDebugInfo, "nextAuthCookieDebugInfo");
|
|
56
|
+
|
|
57
|
+
// src/auth/middleware.ts
|
|
58
|
+
var defaultPublicApiMethods = {
|
|
59
|
+
"/api/contacts": [
|
|
60
|
+
"POST"
|
|
61
|
+
],
|
|
62
|
+
"/api/form-submissions": [
|
|
63
|
+
"POST"
|
|
64
|
+
],
|
|
65
|
+
"/api/blogs": [
|
|
66
|
+
"GET"
|
|
67
|
+
],
|
|
68
|
+
"/api/forms": [
|
|
69
|
+
"GET"
|
|
70
|
+
],
|
|
71
|
+
"/api/auth": [
|
|
72
|
+
"GET",
|
|
73
|
+
"POST"
|
|
74
|
+
],
|
|
75
|
+
"/api/health": [
|
|
76
|
+
"GET"
|
|
77
|
+
],
|
|
78
|
+
"/api/users/forgot-password": [
|
|
79
|
+
"POST"
|
|
80
|
+
],
|
|
81
|
+
"/api/users/set-password": [
|
|
82
|
+
"POST"
|
|
83
|
+
],
|
|
84
|
+
"/api/users/invite": [
|
|
85
|
+
"GET",
|
|
86
|
+
"POST"
|
|
87
|
+
],
|
|
88
|
+
/** Public keys only (e.g. googleEnabled); secrets stay private in the settings handler. */
|
|
89
|
+
"/api/settings/auth_providers": [
|
|
90
|
+
"GET"
|
|
91
|
+
]
|
|
92
|
+
};
|
|
93
|
+
function legacyGetSessionToken(request) {
|
|
94
|
+
const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
|
|
95
|
+
const regular = request.cookies.get("next-auth.session-token")?.value;
|
|
96
|
+
return secure ?? regular;
|
|
97
|
+
}
|
|
98
|
+
__name(legacyGetSessionToken, "legacyGetSessionToken");
|
|
99
|
+
function sessionCookiePresence(request) {
|
|
100
|
+
const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
|
|
101
|
+
const regular = request.cookies.get("next-auth.session-token")?.value;
|
|
102
|
+
const hasChunked = Boolean(request.cookies.get("next-auth.session-token.0")?.value) || Boolean(request.cookies.get("__Secure-next-auth.session-token.0")?.value);
|
|
103
|
+
return {
|
|
104
|
+
hasSecureToken: Boolean(secure),
|
|
105
|
+
hasRegularToken: Boolean(regular),
|
|
106
|
+
hasChunkedToken: hasChunked,
|
|
107
|
+
resolved: Boolean(secure ?? regular ?? hasChunked)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
__name(sessionCookiePresence, "sessionCookiePresence");
|
|
111
|
+
function isPublicMethod(pathname, method, publicApiMethods) {
|
|
112
|
+
for (const [endpoint, methods] of Object.entries(publicApiMethods)) {
|
|
113
|
+
if (pathname.startsWith(endpoint) && methods.includes(method)) return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
__name(isPublicMethod, "isPublicMethod");
|
|
118
|
+
async function hasValidSession(request, secret, legacyGetToken) {
|
|
119
|
+
const presence = sessionCookiePresence(request);
|
|
120
|
+
if (presence.resolved || presence.hasChunkedToken) return true;
|
|
121
|
+
if (request.req) {
|
|
122
|
+
try {
|
|
123
|
+
const { getToken } = await import('next-auth/jwt');
|
|
124
|
+
const token = await getToken({
|
|
125
|
+
req: request.req,
|
|
126
|
+
secret
|
|
127
|
+
});
|
|
128
|
+
if (token != null) return true;
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return Boolean(legacyGetToken(request));
|
|
133
|
+
}
|
|
134
|
+
__name(hasValidSession, "hasValidSession");
|
|
135
|
+
function createCmsMiddleware(config = {}) {
|
|
136
|
+
const { publicAdminPaths = [
|
|
137
|
+
"/admin/signin",
|
|
138
|
+
"/admin/forgot-password",
|
|
139
|
+
"/admin/reset-password",
|
|
140
|
+
"/admin/invite"
|
|
141
|
+
], publicApiMethods = defaultPublicApiMethods, signInPath = "/admin/signin", getSessionToken = legacyGetSessionToken, secret = process.env.NEXTAUTH_SECRET } = config;
|
|
142
|
+
return /* @__PURE__ */ __name(async function cmsMiddleware(request) {
|
|
143
|
+
const pathname = request.nextUrl.pathname;
|
|
144
|
+
const method = request.method;
|
|
145
|
+
if (publicAdminPaths.some((p) => pathname === p || pathname.startsWith(p + "/"))) {
|
|
146
|
+
return {
|
|
147
|
+
type: "next"
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (pathname.startsWith("/admin")) {
|
|
151
|
+
const authenticated = await hasValidSession(request, secret, getSessionToken);
|
|
152
|
+
const cookies = sessionCookiePresence(request);
|
|
153
|
+
if (!authenticated) {
|
|
154
|
+
logAuth("middleware: admin redirect to signin (no session)", {
|
|
155
|
+
pathname,
|
|
156
|
+
method,
|
|
157
|
+
usesGetToken: Boolean(request.req),
|
|
158
|
+
...cookies,
|
|
159
|
+
expectedCookieName: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token"
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
type: "redirect",
|
|
163
|
+
url: new URL(signInPath, request.url).toString()
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
logAuth("middleware: admin allowed", {
|
|
167
|
+
pathname,
|
|
168
|
+
method,
|
|
169
|
+
usesGetToken: Boolean(request.req),
|
|
170
|
+
...cookies
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (pathname.startsWith("/api")) {
|
|
174
|
+
if (isPublicMethod(pathname, method, publicApiMethods)) {
|
|
175
|
+
return {
|
|
176
|
+
type: "next"
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const authenticated = await hasValidSession(request, secret, getSessionToken);
|
|
180
|
+
if (!authenticated) {
|
|
181
|
+
logAuth("middleware: api 401 (no session)", {
|
|
182
|
+
pathname,
|
|
183
|
+
method,
|
|
184
|
+
usesGetToken: Boolean(request.req),
|
|
185
|
+
...sessionCookiePresence(request)
|
|
186
|
+
});
|
|
187
|
+
return {
|
|
188
|
+
type: "json",
|
|
189
|
+
status: 401,
|
|
190
|
+
body: {
|
|
191
|
+
error: "Unauthorized"
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
type: "next"
|
|
198
|
+
};
|
|
199
|
+
}, "cmsMiddleware");
|
|
200
|
+
}
|
|
201
|
+
__name(createCmsMiddleware, "createCmsMiddleware");
|
|
202
|
+
|
|
203
|
+
export { createCmsMiddleware, defaultPublicApiMethods, isAuthDebugClientEnabled, isAuthDebugEnabled, logAuth, logAuthClient, nextAuthCookieDebugInfo, summarizeSessionUserForLog };
|