@infuro/cms-core 1.0.31 → 1.0.34
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/README.md +12 -8
- package/dist/admin.cjs +1907 -1144
- package/dist/admin.cjs.map +1 -1
- package/dist/admin.d.cts +7 -2
- package/dist/admin.d.ts +7 -2
- package/dist/admin.js +1955 -1191
- package/dist/admin.js.map +1 -1
- package/dist/api.cjs +2704 -914
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.js +2664 -875
- package/dist/api.js.map +1 -1
- package/dist/auth.cjs +251 -23
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +53 -22
- package/dist/auth.d.ts +53 -22
- package/dist/auth.js +240 -23
- package/dist/auth.js.map +1 -1
- package/dist/cli.cjs +42 -2
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +42 -2
- package/dist/cli.js.map +1 -1
- package/dist/{index-BcMRGNjS.d.cts → index-Bf5GO8fu.d.cts} +4 -3
- package/dist/{index-Bda8D1Rm.d.ts → index-DOiJuMQA.d.ts} +4 -3
- package/dist/index.cjs +3408 -1284
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +121 -35
- package/dist/index.d.ts +121 -35
- package/dist/index.js +3334 -1226
- package/dist/index.js.map +1 -1
- package/dist/migrations/1778660000003-AddQrTokenToOrders.ts +32 -0
- package/dist/migrations/1778660000004-CreateCustomerAndCustomerContacts.ts +99 -0
- package/dist/migrations/1778660000005-AddCustomerIdToVendorCustomers.ts +39 -0
- package/dist/migrations/1778660000006-UpdateVendorCustomersContactNullable.ts +36 -0
- package/dist/migrations/1778660000007-VendorOwnerCustomerContactsPermission.ts +39 -0
- package/dist/migrations/1779100000000-ChatConversationLeadEmailSent.ts +16 -0
- package/dist/migrations/1779200000000-LlmAgentScope.ts +72 -0
- package/dist/migrations/1779300000000-VendorOwnerContactsPermission.ts +39 -0
- package/dist/migrations/1779400000000-AddCustomerContactIdToOrders.ts +33 -0
- package/package.json +5 -3
package/dist/auth.cjs
CHANGED
|
@@ -94,6 +94,30 @@ var init_permission_entities = __esm({
|
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
+
// src/auth/role-helpers.ts
|
|
98
|
+
function isSuperAdmin(user) {
|
|
99
|
+
if (!user) return false;
|
|
100
|
+
if (user.groupId === SUPER_ADMIN_GROUP_ID) return true;
|
|
101
|
+
if (user.isRBACAdmin === true) return true;
|
|
102
|
+
return isSuperAdminGroupName(user.groupName);
|
|
103
|
+
}
|
|
104
|
+
function isVendorAdmin(user) {
|
|
105
|
+
if (!user?.email || isSuperAdmin(user)) return false;
|
|
106
|
+
if (user.groupId === VENDOR_ADMIN_GROUP_ID) return true;
|
|
107
|
+
if ((user.vendorIds?.length ?? 0) > 0) return true;
|
|
108
|
+
return isVendorGroupName(user.groupName);
|
|
109
|
+
}
|
|
110
|
+
var SUPER_ADMIN_GROUP_ID, VENDOR_ADMIN_GROUP_ID;
|
|
111
|
+
var init_role_helpers = __esm({
|
|
112
|
+
"src/auth/role-helpers.ts"() {
|
|
113
|
+
"use strict";
|
|
114
|
+
init_permission_entities();
|
|
115
|
+
init_vendor_scope();
|
|
116
|
+
SUPER_ADMIN_GROUP_ID = 1;
|
|
117
|
+
VENDOR_ADMIN_GROUP_ID = 5;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
97
121
|
// src/auth/vendor-scope.ts
|
|
98
122
|
function isVendorGroupName(name) {
|
|
99
123
|
if (!name?.trim()) return false;
|
|
@@ -102,12 +126,12 @@ function isVendorGroupName(name) {
|
|
|
102
126
|
}
|
|
103
127
|
function isPlatformAdministrator(user) {
|
|
104
128
|
if (!user?.email) return false;
|
|
105
|
-
return
|
|
129
|
+
return isSuperAdmin(user);
|
|
106
130
|
}
|
|
107
131
|
function isVendorPortalUser(user) {
|
|
108
132
|
if (user?.isVendorPortal === true) return true;
|
|
109
133
|
if (!user?.email || isPlatformAdministrator(user)) return false;
|
|
110
|
-
if ((user
|
|
134
|
+
if (isVendorAdmin(user)) return true;
|
|
111
135
|
return isVendorGroupName(user.groupName);
|
|
112
136
|
}
|
|
113
137
|
function isVendorStaff(user) {
|
|
@@ -149,7 +173,7 @@ var VENDOR_SCOPED_STORE_ENTITIES, VENDOR_STORE_RBAC_ENTITIES, VENDOR_OWNER_GROUP
|
|
|
149
173
|
var init_vendor_scope = __esm({
|
|
150
174
|
"src/auth/vendor-scope.ts"() {
|
|
151
175
|
"use strict";
|
|
152
|
-
|
|
176
|
+
init_role_helpers();
|
|
153
177
|
VENDOR_SCOPED_STORE_ENTITIES = /* @__PURE__ */ new Set([
|
|
154
178
|
"products",
|
|
155
179
|
"collections",
|
|
@@ -370,6 +394,8 @@ __export(auth_exports, {
|
|
|
370
394
|
OPEN_ENDPOINTS: () => OPEN_ENDPOINTS,
|
|
371
395
|
PERMISSION_REQUIRED_ENDPOINTS: () => PERMISSION_REQUIRED_ENDPOINTS,
|
|
372
396
|
RBAC_ADMIN_ONLY_ENTITIES: () => RBAC_ADMIN_ONLY_ENTITIES,
|
|
397
|
+
SUPER_ADMIN_GROUP_ID: () => SUPER_ADMIN_GROUP_ID,
|
|
398
|
+
VENDOR_ADMIN_GROUP_ID: () => VENDOR_ADMIN_GROUP_ID,
|
|
373
399
|
VENDOR_OWNER_GROUP_NAME: () => VENDOR_OWNER_GROUP_NAME,
|
|
374
400
|
VENDOR_SCOPED_STORE_ENTITIES: () => VENDOR_SCOPED_STORE_ENTITIES,
|
|
375
401
|
VENDOR_STORE_RBAC_ENTITIES: () => VENDOR_STORE_RBAC_ENTITIES,
|
|
@@ -385,23 +411,32 @@ __export(auth_exports, {
|
|
|
385
411
|
getNextAuthOptions: () => getNextAuthOptions,
|
|
386
412
|
getPermissionableEntityKeys: () => getPermissionableEntityKeys,
|
|
387
413
|
getRequiredPermission: () => getRequiredPermission,
|
|
414
|
+
getStorefrontNextAuthOptions: () => getStorefrontNextAuthOptions,
|
|
388
415
|
hasEntityPermission: () => hasEntityPermission,
|
|
416
|
+
isAuthDebugClientEnabled: () => isAuthDebugClientEnabled,
|
|
417
|
+
isAuthDebugEnabled: () => isAuthDebugEnabled,
|
|
389
418
|
isOpenEndpoint: () => isOpenEndpoint,
|
|
390
419
|
isPlatformAdministrator: () => isPlatformAdministrator,
|
|
391
420
|
isPublicMethod: () => isPublicMethod,
|
|
392
421
|
isRbacDebugEnabled: () => isRbacDebugEnabled,
|
|
422
|
+
isSuperAdmin: () => isSuperAdmin,
|
|
393
423
|
isSuperAdminGroupName: () => isSuperAdminGroupName,
|
|
424
|
+
isVendorAdmin: () => isVendorAdmin,
|
|
394
425
|
isVendorGroupName: () => isVendorGroupName,
|
|
395
426
|
isVendorOwner: () => isVendorOwner,
|
|
396
427
|
isVendorPortalUser: () => isVendorPortalUser,
|
|
397
428
|
isVendorStaff: () => isVendorStaff,
|
|
429
|
+
logAuth: () => logAuth,
|
|
430
|
+
logAuthClient: () => logAuthClient,
|
|
398
431
|
logEntityAccessDecision: () => logEntityAccessDecision,
|
|
399
432
|
logRbac: () => logRbac,
|
|
433
|
+
nextAuthCookieDebugInfo: () => nextAuthCookieDebugInfo,
|
|
400
434
|
permissionRowsToRecord: () => permissionRowsToRecord,
|
|
401
435
|
resolveVendorScopeFromSessionUser: () => resolveVendorScopeFromSessionUser,
|
|
402
436
|
seedAdministratorPermissions: () => seedAdministratorPermissions,
|
|
403
437
|
sessionHasEntityAccess: () => sessionHasEntityAccess,
|
|
404
438
|
summarizeEntityPerms: () => summarizeEntityPerms,
|
|
439
|
+
summarizeSessionUserForLog: () => summarizeSessionUserForLog,
|
|
405
440
|
vendorPortalFlagsFromUser: () => vendorPortalFlagsFromUser
|
|
406
441
|
});
|
|
407
442
|
module.exports = __toCommonJS(auth_exports);
|
|
@@ -520,6 +555,7 @@ function createAuthHelpersFromGetSession(getSession, NextResponse) {
|
|
|
520
555
|
|
|
521
556
|
// src/auth/index.ts
|
|
522
557
|
init_rbac_debug();
|
|
558
|
+
init_role_helpers();
|
|
523
559
|
init_vendor_scope();
|
|
524
560
|
init_permission_entities();
|
|
525
561
|
|
|
@@ -556,6 +592,59 @@ async function seedAdministratorPermissions(dataSource, entityMap) {
|
|
|
556
592
|
}
|
|
557
593
|
}
|
|
558
594
|
|
|
595
|
+
// src/auth/middleware.ts
|
|
596
|
+
var import_jwt = require("next-auth/jwt");
|
|
597
|
+
|
|
598
|
+
// src/auth/auth-debug.ts
|
|
599
|
+
var LOG_PREFIX2 = "[cms-auth]";
|
|
600
|
+
function isAuthDebugEnabled() {
|
|
601
|
+
const v = process.env.CMS_AUTH_DEBUG?.trim().toLowerCase();
|
|
602
|
+
if (v === "1" || v === "true" || v === "yes") return true;
|
|
603
|
+
if (v === "0" || v === "false" || v === "no") return false;
|
|
604
|
+
return process.env.NODE_ENV === "development";
|
|
605
|
+
}
|
|
606
|
+
function isAuthDebugClientEnabled() {
|
|
607
|
+
if (typeof window === "undefined") return false;
|
|
608
|
+
const v = process.env.NEXT_PUBLIC_CMS_AUTH_DEBUG?.trim().toLowerCase();
|
|
609
|
+
if (v === "1" || v === "true" || v === "yes") return true;
|
|
610
|
+
if (v === "0" || v === "false" || v === "no") return false;
|
|
611
|
+
return process.env.NODE_ENV === "development";
|
|
612
|
+
}
|
|
613
|
+
function logAuth(message, data) {
|
|
614
|
+
if (!isAuthDebugEnabled()) return;
|
|
615
|
+
if (data) console.info(LOG_PREFIX2, message, data);
|
|
616
|
+
else console.info(LOG_PREFIX2, message);
|
|
617
|
+
}
|
|
618
|
+
function logAuthClient(message, data) {
|
|
619
|
+
if (!isAuthDebugClientEnabled()) return;
|
|
620
|
+
if (data) console.info(LOG_PREFIX2, message, data);
|
|
621
|
+
else console.info(LOG_PREFIX2, message);
|
|
622
|
+
}
|
|
623
|
+
function summarizeSessionUserForLog(user) {
|
|
624
|
+
if (!user || typeof user !== "object") return { present: false };
|
|
625
|
+
const u = user;
|
|
626
|
+
return {
|
|
627
|
+
present: true,
|
|
628
|
+
email: u.email ?? null,
|
|
629
|
+
id: u.id ?? null,
|
|
630
|
+
adminAccess: u.adminAccess ?? null,
|
|
631
|
+
isRBACAdmin: u.isRBACAdmin ?? null,
|
|
632
|
+
isVendorPortal: u.isVendorPortal ?? null,
|
|
633
|
+
groupName: u.groupName ?? null
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
function nextAuthCookieDebugInfo() {
|
|
637
|
+
const nextAuthUrl = process.env.NEXTAUTH_URL ?? "(unset)";
|
|
638
|
+
const isHttps = nextAuthUrl.startsWith("https");
|
|
639
|
+
return {
|
|
640
|
+
nextAuthUrl,
|
|
641
|
+
hasSecret: Boolean(process.env.NEXTAUTH_SECRET),
|
|
642
|
+
cookieName: isHttps ? "__Secure-next-auth.session-token" : "next-auth.session-token",
|
|
643
|
+
cookieSecure: isHttps,
|
|
644
|
+
nodeEnv: process.env.NODE_ENV ?? "(unset)"
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
|
|
559
648
|
// src/auth/middleware.ts
|
|
560
649
|
var defaultPublicApiMethods = {
|
|
561
650
|
"/api/contacts": ["POST"],
|
|
@@ -568,8 +657,21 @@ var defaultPublicApiMethods = {
|
|
|
568
657
|
"/api/users/set-password": ["POST"],
|
|
569
658
|
"/api/users/invite": ["POST"]
|
|
570
659
|
};
|
|
571
|
-
function
|
|
572
|
-
|
|
660
|
+
function legacyGetSessionToken(request) {
|
|
661
|
+
const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
|
|
662
|
+
const regular = request.cookies.get("next-auth.session-token")?.value;
|
|
663
|
+
return secure ?? regular;
|
|
664
|
+
}
|
|
665
|
+
function sessionCookiePresence(request) {
|
|
666
|
+
const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
|
|
667
|
+
const regular = request.cookies.get("next-auth.session-token")?.value;
|
|
668
|
+
const hasChunked = Boolean(request.cookies.get("next-auth.session-token.0")?.value) || Boolean(request.cookies.get("__Secure-next-auth.session-token.0")?.value);
|
|
669
|
+
return {
|
|
670
|
+
hasSecureToken: Boolean(secure),
|
|
671
|
+
hasRegularToken: Boolean(regular),
|
|
672
|
+
hasChunkedToken: hasChunked,
|
|
673
|
+
resolved: Boolean(secure ?? regular)
|
|
674
|
+
};
|
|
573
675
|
}
|
|
574
676
|
function isPublicMethod2(pathname, method, publicApiMethods) {
|
|
575
677
|
for (const [endpoint, methods] of Object.entries(publicApiMethods)) {
|
|
@@ -577,31 +679,59 @@ function isPublicMethod2(pathname, method, publicApiMethods) {
|
|
|
577
679
|
}
|
|
578
680
|
return false;
|
|
579
681
|
}
|
|
682
|
+
async function hasValidSession(request, secret, legacyGetToken) {
|
|
683
|
+
if (request.req) {
|
|
684
|
+
const token = await (0, import_jwt.getToken)({ req: request.req, secret });
|
|
685
|
+
return token != null;
|
|
686
|
+
}
|
|
687
|
+
return Boolean(legacyGetToken(request));
|
|
688
|
+
}
|
|
580
689
|
function createCmsMiddleware(config = {}) {
|
|
581
690
|
const {
|
|
582
691
|
publicAdminPaths = ["/admin/signin", "/admin/forgot-password", "/admin/reset-password", "/admin/invite"],
|
|
583
692
|
publicApiMethods = defaultPublicApiMethods,
|
|
584
693
|
signInPath = "/admin/signin",
|
|
585
|
-
getSessionToken =
|
|
694
|
+
getSessionToken = legacyGetSessionToken,
|
|
695
|
+
secret = process.env.NEXTAUTH_SECRET
|
|
586
696
|
} = config;
|
|
587
|
-
return function cmsMiddleware(request) {
|
|
697
|
+
return async function cmsMiddleware(request) {
|
|
588
698
|
const pathname = request.nextUrl.pathname;
|
|
589
699
|
const method = request.method;
|
|
590
700
|
if (publicAdminPaths.some((p) => pathname === p || pathname.startsWith(p + "/"))) {
|
|
591
701
|
return { type: "next" };
|
|
592
702
|
}
|
|
593
703
|
if (pathname.startsWith("/admin")) {
|
|
594
|
-
const
|
|
595
|
-
|
|
704
|
+
const authenticated = await hasValidSession(request, secret, getSessionToken);
|
|
705
|
+
const cookies = sessionCookiePresence(request);
|
|
706
|
+
if (!authenticated) {
|
|
707
|
+
logAuth("middleware: admin redirect to signin (no session)", {
|
|
708
|
+
pathname,
|
|
709
|
+
method,
|
|
710
|
+
usesGetToken: Boolean(request.req),
|
|
711
|
+
...cookies,
|
|
712
|
+
expectedCookieName: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token"
|
|
713
|
+
});
|
|
596
714
|
return { type: "redirect", url: new URL(signInPath, request.url).toString() };
|
|
597
715
|
}
|
|
716
|
+
logAuth("middleware: admin allowed", {
|
|
717
|
+
pathname,
|
|
718
|
+
method,
|
|
719
|
+
usesGetToken: Boolean(request.req),
|
|
720
|
+
...cookies
|
|
721
|
+
});
|
|
598
722
|
}
|
|
599
723
|
if (pathname.startsWith("/api")) {
|
|
600
724
|
if (isPublicMethod2(pathname, method, publicApiMethods)) {
|
|
601
725
|
return { type: "next" };
|
|
602
726
|
}
|
|
603
|
-
const
|
|
604
|
-
if (!
|
|
727
|
+
const authenticated = await hasValidSession(request, secret, getSessionToken);
|
|
728
|
+
if (!authenticated) {
|
|
729
|
+
logAuth("middleware: api 401 (no session)", {
|
|
730
|
+
pathname,
|
|
731
|
+
method,
|
|
732
|
+
usesGetToken: Boolean(request.req),
|
|
733
|
+
...sessionCookiePresence(request)
|
|
734
|
+
});
|
|
605
735
|
return { type: "json", status: 401, body: { error: "Unauthorized" } };
|
|
606
736
|
}
|
|
607
737
|
}
|
|
@@ -612,11 +742,16 @@ function createCmsMiddleware(config = {}) {
|
|
|
612
742
|
// src/auth/nextauth-options.ts
|
|
613
743
|
var import_credentials = __toESM(require("next-auth/providers/credentials"), 1);
|
|
614
744
|
init_permission_entities();
|
|
745
|
+
init_role_helpers();
|
|
615
746
|
init_vendor_scope();
|
|
616
747
|
var CredentialsProvider = import_credentials.default.default ?? import_credentials.default;
|
|
617
748
|
function sessionUserFromNextAuthUser(user) {
|
|
618
749
|
const g = user.group;
|
|
619
|
-
const isRBACAdmin =
|
|
750
|
+
const isRBACAdmin = isSuperAdmin({
|
|
751
|
+
groupId: user.groupId ?? void 0,
|
|
752
|
+
groupName: g?.name,
|
|
753
|
+
isRBACAdmin: false
|
|
754
|
+
});
|
|
620
755
|
const entityPerms = permissionRowsToRecord(g?.permissions);
|
|
621
756
|
const rawAdminAccess = user.adminAccess;
|
|
622
757
|
const adminAccess = rawAdminAccess === true ? true : rawAdminAccess === false ? false : void 0;
|
|
@@ -645,6 +780,26 @@ function sessionUserFromNextAuthUser(user) {
|
|
|
645
780
|
isVendorOwner: isVendorOwner2
|
|
646
781
|
};
|
|
647
782
|
}
|
|
783
|
+
function isCustomerGroupUser(user) {
|
|
784
|
+
return user.group?.name?.toLocaleLowerCase().trim() === "customer";
|
|
785
|
+
}
|
|
786
|
+
function callbackUrlTargetsAdmin(callbackUrl) {
|
|
787
|
+
const raw = callbackUrl.trim();
|
|
788
|
+
if (!raw) return false;
|
|
789
|
+
if (raw.startsWith("/admin")) return true;
|
|
790
|
+
try {
|
|
791
|
+
const path = raw.startsWith("http") ? new URL(raw).pathname : raw.split("?")[0] ?? raw;
|
|
792
|
+
return path.startsWith("/admin");
|
|
793
|
+
} catch {
|
|
794
|
+
return raw.includes("/admin");
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
function permitsCustomerLogin(allowCustomerLogin, credentials) {
|
|
798
|
+
if (allowCustomerLogin === true) return true;
|
|
799
|
+
if (allowCustomerLogin === false) return false;
|
|
800
|
+
const callbackUrl = typeof credentials?.callbackUrl === "string" ? credentials.callbackUrl : "";
|
|
801
|
+
return !callbackUrlTargetsAdmin(callbackUrl);
|
|
802
|
+
}
|
|
648
803
|
function getNextAuthOptions(config) {
|
|
649
804
|
const {
|
|
650
805
|
getUserByEmail,
|
|
@@ -654,8 +809,10 @@ function getNextAuthOptions(config) {
|
|
|
654
809
|
extend,
|
|
655
810
|
enablePasswordLogin = true,
|
|
656
811
|
enableOtpLogin = false,
|
|
657
|
-
authorizeOtp
|
|
812
|
+
authorizeOtp,
|
|
813
|
+
allowCustomerLogin
|
|
658
814
|
} = config;
|
|
815
|
+
logAuth("getNextAuthOptions init", nextAuthCookieDebugInfo());
|
|
659
816
|
const providers = [];
|
|
660
817
|
if (enablePasswordLogin) {
|
|
661
818
|
providers.push(
|
|
@@ -666,15 +823,53 @@ function getNextAuthOptions(config) {
|
|
|
666
823
|
password: { label: "Password", type: "password" }
|
|
667
824
|
},
|
|
668
825
|
async authorize(credentials) {
|
|
669
|
-
|
|
826
|
+
const creds = credentials;
|
|
827
|
+
const email = creds?.email?.trim() ?? "";
|
|
828
|
+
if (!email || !creds?.password) {
|
|
829
|
+
logAuth("authorize(credentials) rejected", { reason: "missing_email_or_password" });
|
|
830
|
+
return null;
|
|
831
|
+
}
|
|
670
832
|
try {
|
|
671
|
-
const user = await getUserByEmail(
|
|
672
|
-
if (!user
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
833
|
+
const user = await getUserByEmail(email);
|
|
834
|
+
if (!user) {
|
|
835
|
+
logAuth("authorize(credentials) rejected", { reason: "user_not_found", email });
|
|
836
|
+
return null;
|
|
837
|
+
}
|
|
838
|
+
if (user.blocked) {
|
|
839
|
+
logAuth("authorize(credentials) rejected", { reason: "blocked", email, userId: user.id });
|
|
840
|
+
return null;
|
|
841
|
+
}
|
|
842
|
+
if (user.deleted) {
|
|
843
|
+
logAuth("authorize(credentials) rejected", { reason: "deleted", email, userId: user.id });
|
|
844
|
+
return null;
|
|
845
|
+
}
|
|
846
|
+
if (!user.password) {
|
|
847
|
+
logAuth("authorize(credentials) rejected", { reason: "no_password", email, userId: user.id });
|
|
848
|
+
return null;
|
|
849
|
+
}
|
|
850
|
+
const valid = await comparePassword(creds.password, user.password);
|
|
851
|
+
if (!valid) {
|
|
852
|
+
logAuth("authorize(credentials) rejected", { reason: "invalid_password", email, userId: user.id });
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
if (isCustomerGroupUser(user) && !permitsCustomerLogin(allowCustomerLogin, creds)) {
|
|
856
|
+
logAuth("authorize(credentials) rejected", {
|
|
857
|
+
reason: "customer_group",
|
|
858
|
+
email,
|
|
859
|
+
userId: user.id,
|
|
860
|
+
callbackUrl: creds?.callbackUrl ?? null
|
|
861
|
+
});
|
|
862
|
+
return null;
|
|
863
|
+
}
|
|
864
|
+
const sessionUser = sessionUserFromNextAuthUser(user);
|
|
865
|
+
logAuth("authorize(credentials) ok", summarizeSessionUserForLog(sessionUser));
|
|
866
|
+
return sessionUser;
|
|
676
867
|
} catch (err) {
|
|
677
868
|
console.error("[cms-auth] authorize error (credentials):", err instanceof Error ? err.message : err);
|
|
869
|
+
logAuth("authorize(credentials) error", {
|
|
870
|
+
email,
|
|
871
|
+
message: err instanceof Error ? err.message : String(err)
|
|
872
|
+
});
|
|
678
873
|
return null;
|
|
679
874
|
}
|
|
680
875
|
}
|
|
@@ -692,13 +887,22 @@ function getNextAuthOptions(config) {
|
|
|
692
887
|
channel: { label: "Channel", type: "text" }
|
|
693
888
|
},
|
|
694
889
|
async authorize(credentials) {
|
|
695
|
-
const
|
|
696
|
-
const
|
|
697
|
-
const
|
|
890
|
+
const creds = credentials;
|
|
891
|
+
const identifier = typeof creds?.identifier === "string" ? creds.identifier.trim() : "";
|
|
892
|
+
const code = typeof creds?.code === "string" ? creds.code.trim() : "";
|
|
893
|
+
const ch = creds?.channel === "sms" ? "sms" : "email";
|
|
698
894
|
if (!identifier || !code) return null;
|
|
699
895
|
try {
|
|
700
896
|
const user = await authorizeOtp({ identifier, channel: ch, code });
|
|
701
897
|
if (!user || user.blocked || user.deleted) return null;
|
|
898
|
+
if (isCustomerGroupUser(user) && !permitsCustomerLogin(allowCustomerLogin, creds)) {
|
|
899
|
+
logAuth("authorize(otp) rejected", {
|
|
900
|
+
reason: "customer_group",
|
|
901
|
+
identifier,
|
|
902
|
+
callbackUrl: creds?.callbackUrl ?? null
|
|
903
|
+
});
|
|
904
|
+
return null;
|
|
905
|
+
}
|
|
702
906
|
return sessionUserFromNextAuthUser(user);
|
|
703
907
|
} catch (err) {
|
|
704
908
|
console.error("[cms-auth] authorize error (otp):", err instanceof Error ? err.message : err);
|
|
@@ -727,6 +931,10 @@ function getNextAuthOptions(config) {
|
|
|
727
931
|
callbacks: {
|
|
728
932
|
async jwt({ token, user, trigger, session }) {
|
|
729
933
|
if (user) {
|
|
934
|
+
logAuth("jwt callback: new sign-in", {
|
|
935
|
+
trigger,
|
|
936
|
+
user: summarizeSessionUserForLog(user)
|
|
937
|
+
});
|
|
730
938
|
const u = user;
|
|
731
939
|
token.id = u.id;
|
|
732
940
|
token.groupId = u.groupId;
|
|
@@ -741,6 +949,7 @@ function getNextAuthOptions(config) {
|
|
|
741
949
|
token.isVendorOwner = u.isVendorOwner;
|
|
742
950
|
}
|
|
743
951
|
if (trigger === "update" && session && typeof session === "object") {
|
|
952
|
+
logAuth("jwt callback: session update", { trigger });
|
|
744
953
|
const s = session;
|
|
745
954
|
const t = token;
|
|
746
955
|
if (typeof s.name === "string") t.name = s.name;
|
|
@@ -750,8 +959,13 @@ function getNextAuthOptions(config) {
|
|
|
750
959
|
return token;
|
|
751
960
|
},
|
|
752
961
|
async session({ session, token }) {
|
|
962
|
+
const t = token;
|
|
963
|
+
logAuth("session callback", {
|
|
964
|
+
tokenHasId: t.id != null,
|
|
965
|
+
tokenEmail: typeof t.email === "string" ? t.email : null,
|
|
966
|
+
sessionUser: summarizeSessionUserForLog(session.user)
|
|
967
|
+
});
|
|
753
968
|
if (session.user) {
|
|
754
|
-
const t = token;
|
|
755
969
|
if (typeof t.name === "string") session.user.name = t.name;
|
|
756
970
|
if (typeof t.email === "string") session.user.email = t.email;
|
|
757
971
|
session.user.id = t.id;
|
|
@@ -772,12 +986,17 @@ function getNextAuthOptions(config) {
|
|
|
772
986
|
};
|
|
773
987
|
return extend ? extend(options) : options;
|
|
774
988
|
}
|
|
989
|
+
function getStorefrontNextAuthOptions(config) {
|
|
990
|
+
return getNextAuthOptions({ ...config, allowCustomerLogin: true });
|
|
991
|
+
}
|
|
775
992
|
// Annotate the CommonJS export names for ESM import in node:
|
|
776
993
|
0 && (module.exports = {
|
|
777
994
|
ADMIN_GROUP_NAME,
|
|
778
995
|
OPEN_ENDPOINTS,
|
|
779
996
|
PERMISSION_REQUIRED_ENDPOINTS,
|
|
780
997
|
RBAC_ADMIN_ONLY_ENTITIES,
|
|
998
|
+
SUPER_ADMIN_GROUP_ID,
|
|
999
|
+
VENDOR_ADMIN_GROUP_ID,
|
|
781
1000
|
VENDOR_OWNER_GROUP_NAME,
|
|
782
1001
|
VENDOR_SCOPED_STORE_ENTITIES,
|
|
783
1002
|
VENDOR_STORE_RBAC_ENTITIES,
|
|
@@ -793,23 +1012,32 @@ function getNextAuthOptions(config) {
|
|
|
793
1012
|
getNextAuthOptions,
|
|
794
1013
|
getPermissionableEntityKeys,
|
|
795
1014
|
getRequiredPermission,
|
|
1015
|
+
getStorefrontNextAuthOptions,
|
|
796
1016
|
hasEntityPermission,
|
|
1017
|
+
isAuthDebugClientEnabled,
|
|
1018
|
+
isAuthDebugEnabled,
|
|
797
1019
|
isOpenEndpoint,
|
|
798
1020
|
isPlatformAdministrator,
|
|
799
1021
|
isPublicMethod,
|
|
800
1022
|
isRbacDebugEnabled,
|
|
1023
|
+
isSuperAdmin,
|
|
801
1024
|
isSuperAdminGroupName,
|
|
1025
|
+
isVendorAdmin,
|
|
802
1026
|
isVendorGroupName,
|
|
803
1027
|
isVendorOwner,
|
|
804
1028
|
isVendorPortalUser,
|
|
805
1029
|
isVendorStaff,
|
|
1030
|
+
logAuth,
|
|
1031
|
+
logAuthClient,
|
|
806
1032
|
logEntityAccessDecision,
|
|
807
1033
|
logRbac,
|
|
1034
|
+
nextAuthCookieDebugInfo,
|
|
808
1035
|
permissionRowsToRecord,
|
|
809
1036
|
resolveVendorScopeFromSessionUser,
|
|
810
1037
|
seedAdministratorPermissions,
|
|
811
1038
|
sessionHasEntityAccess,
|
|
812
1039
|
summarizeEntityPerms,
|
|
1040
|
+
summarizeSessionUserForLog,
|
|
813
1041
|
vendorPortalFlagsFromUser
|
|
814
1042
|
});
|
|
815
1043
|
//# sourceMappingURL=auth.cjs.map
|