@mesob/auth-hono 0.0.7 → 0.0.8
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/index.js +182 -125
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -449,9 +449,9 @@ var findSessionByToken = (db, hashedToken) => {
|
|
|
449
449
|
};
|
|
450
450
|
|
|
451
451
|
// src/db/orm/iam/users/find-user-by-id.ts
|
|
452
|
-
import { and as and2, eq as eq2 } from "drizzle-orm";
|
|
453
|
-
var findUserById = (db, tenantId, userId) => {
|
|
454
|
-
return db.select({
|
|
452
|
+
import { and as and2, eq as eq2, sql as sql2 } from "drizzle-orm";
|
|
453
|
+
var findUserById = async (db, tenantId, userId) => {
|
|
454
|
+
return await db.select({
|
|
455
455
|
id: usersInIam.id,
|
|
456
456
|
tenantId: usersInIam.tenantId,
|
|
457
457
|
fullName: usersInIam.fullName,
|
|
@@ -461,8 +461,34 @@ var findUserById = (db, tenantId, userId) => {
|
|
|
461
461
|
image: usersInIam.image,
|
|
462
462
|
emailVerified: usersInIam.emailVerified,
|
|
463
463
|
phoneVerified: usersInIam.phoneVerified,
|
|
464
|
-
lastSignInAt: usersInIam.lastSignInAt
|
|
465
|
-
|
|
464
|
+
lastSignInAt: usersInIam.lastSignInAt,
|
|
465
|
+
userRoles: sql2`
|
|
466
|
+
COALESCE(
|
|
467
|
+
json_agg(
|
|
468
|
+
json_build_object(
|
|
469
|
+
'id', ${userRolesInIam.id},
|
|
470
|
+
'roleId', ${rolesInIam.id},
|
|
471
|
+
'code', ${rolesInIam.code},
|
|
472
|
+
'name', ${rolesInIam.name},
|
|
473
|
+
'description', ${rolesInIam.description}
|
|
474
|
+
)
|
|
475
|
+
) FILTER (WHERE ${userRolesInIam.id} IS NOT NULL),
|
|
476
|
+
'[]'::json
|
|
477
|
+
)
|
|
478
|
+
`
|
|
479
|
+
}).from(usersInIam).leftJoin(
|
|
480
|
+
userRolesInIam,
|
|
481
|
+
and2(
|
|
482
|
+
eq2(userRolesInIam.userId, usersInIam.id),
|
|
483
|
+
eq2(userRolesInIam.tenantId, tenantId)
|
|
484
|
+
)
|
|
485
|
+
).leftJoin(
|
|
486
|
+
rolesInIam,
|
|
487
|
+
and2(
|
|
488
|
+
eq2(userRolesInIam.roleId, rolesInIam.id),
|
|
489
|
+
eq2(rolesInIam.tenantId, tenantId)
|
|
490
|
+
)
|
|
491
|
+
).where(and2(eq2(usersInIam.id, userId), eq2(usersInIam.tenantId, tenantId))).groupBy(usersInIam.id).limit(1).then(([user]) => user || null);
|
|
466
492
|
};
|
|
467
493
|
|
|
468
494
|
// src/handler.ts
|
|
@@ -470,24 +496,6 @@ import { OpenAPIHono as OpenAPIHono2 } from "@hono/zod-openapi";
|
|
|
470
496
|
import { getCookie as getCookie3 } from "hono/cookie";
|
|
471
497
|
import { HTTPException as HTTPException16 } from "hono/http-exception";
|
|
472
498
|
|
|
473
|
-
// src/db/orm/iam/users/find-user-roles.ts
|
|
474
|
-
import { and as and3, eq as eq3 } from "drizzle-orm";
|
|
475
|
-
var findUserRoles = (db, tenantId, userId) => {
|
|
476
|
-
return db.select({
|
|
477
|
-
id: userRolesInIam.id,
|
|
478
|
-
roleId: rolesInIam.id,
|
|
479
|
-
code: rolesInIam.code,
|
|
480
|
-
name: rolesInIam.name,
|
|
481
|
-
description: rolesInIam.description
|
|
482
|
-
}).from(userRolesInIam).innerJoin(rolesInIam, eq3(userRolesInIam.roleId, rolesInIam.id)).where(
|
|
483
|
-
and3(
|
|
484
|
-
eq3(userRolesInIam.userId, userId),
|
|
485
|
-
eq3(userRolesInIam.tenantId, tenantId),
|
|
486
|
-
eq3(rolesInIam.tenantId, tenantId)
|
|
487
|
-
)
|
|
488
|
-
);
|
|
489
|
-
};
|
|
490
|
-
|
|
491
499
|
// src/lib/crypto.ts
|
|
492
500
|
import { scrypt } from "@noble/hashes/scrypt.js";
|
|
493
501
|
import { randomBytes } from "@noble/hashes/utils.js";
|
|
@@ -708,24 +716,24 @@ var pendingAccountChangeResponseSchema = z.object({
|
|
|
708
716
|
import { HTTPException as HTTPException2 } from "hono/http-exception";
|
|
709
717
|
|
|
710
718
|
// src/db/orm/iam/account-changes/expire-pending-account-changes.ts
|
|
711
|
-
import { and as
|
|
719
|
+
import { and as and3, eq as eq3, lte } from "drizzle-orm";
|
|
712
720
|
var expirePendingAccountChanges = (db, tenantId, userId) => {
|
|
713
721
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
714
722
|
return db.update(accountChangesInIam).set({
|
|
715
723
|
status: "expired",
|
|
716
724
|
updatedAt: now
|
|
717
725
|
}).where(
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
726
|
+
and3(
|
|
727
|
+
eq3(accountChangesInIam.tenantId, tenantId),
|
|
728
|
+
eq3(accountChangesInIam.userId, userId),
|
|
729
|
+
eq3(accountChangesInIam.status, "pending"),
|
|
722
730
|
lte(accountChangesInIam.expiresAt, now)
|
|
723
731
|
)
|
|
724
732
|
);
|
|
725
733
|
};
|
|
726
734
|
|
|
727
735
|
// src/db/orm/iam/account-changes/find-pending-account-change.ts
|
|
728
|
-
import { and as
|
|
736
|
+
import { and as and4, desc, eq as eq4, gt as gt2 } from "drizzle-orm";
|
|
729
737
|
var findPendingAccountChange = async (db, tenantId, userId) => {
|
|
730
738
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
731
739
|
return await db.select({
|
|
@@ -734,10 +742,10 @@ var findPendingAccountChange = async (db, tenantId, userId) => {
|
|
|
734
742
|
newPhone: accountChangesInIam.newPhone,
|
|
735
743
|
expiresAt: accountChangesInIam.expiresAt
|
|
736
744
|
}).from(accountChangesInIam).where(
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
745
|
+
and4(
|
|
746
|
+
eq4(accountChangesInIam.tenantId, tenantId),
|
|
747
|
+
eq4(accountChangesInIam.userId, userId),
|
|
748
|
+
eq4(accountChangesInIam.status, "pending"),
|
|
741
749
|
gt2(accountChangesInIam.expiresAt, now)
|
|
742
750
|
)
|
|
743
751
|
).orderBy(desc(accountChangesInIam.createdAt)).limit(1).then(([row]) => {
|
|
@@ -757,18 +765,18 @@ var findPendingAccountChange = async (db, tenantId, userId) => {
|
|
|
757
765
|
};
|
|
758
766
|
|
|
759
767
|
// src/db/orm/iam/verifications/find-active-verification-id.ts
|
|
760
|
-
import { and as
|
|
768
|
+
import { and as and5, desc as desc2, eq as eq5, gt as gt3 } from "drizzle-orm";
|
|
761
769
|
var findActiveVerificationId = async (db, tenantId, userId, type, to) => {
|
|
762
770
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
763
771
|
return await db.select({
|
|
764
772
|
verificationId: verificationsInIam.id,
|
|
765
773
|
expiresAt: verificationsInIam.expiresAt
|
|
766
774
|
}).from(verificationsInIam).where(
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
775
|
+
and5(
|
|
776
|
+
eq5(verificationsInIam.tenantId, tenantId),
|
|
777
|
+
eq5(verificationsInIam.userId, userId),
|
|
778
|
+
eq5(verificationsInIam.type, type),
|
|
779
|
+
eq5(verificationsInIam.to, to),
|
|
772
780
|
gt3(verificationsInIam.expiresAt, now)
|
|
773
781
|
)
|
|
774
782
|
).orderBy(desc2(verificationsInIam.createdAt)).limit(1).then(([row]) => row ? row : null);
|
|
@@ -849,9 +857,9 @@ var accountChangePendingHandler = async (c) => {
|
|
|
849
857
|
};
|
|
850
858
|
|
|
851
859
|
// src/db/orm/iam/users/find-user-by-email.ts
|
|
852
|
-
import { and as
|
|
853
|
-
var findUserByEmail = (db, tenantId, email) => {
|
|
854
|
-
|
|
860
|
+
import { and as and6, eq as eq6, sql as sql3 } from "drizzle-orm";
|
|
861
|
+
var findUserByEmail = async (db, tenantId, email) => {
|
|
862
|
+
const result = await db.select({
|
|
855
863
|
id: usersInIam.id,
|
|
856
864
|
tenantId: usersInIam.tenantId,
|
|
857
865
|
fullName: usersInIam.fullName,
|
|
@@ -861,19 +869,46 @@ var findUserByEmail = (db, tenantId, email) => {
|
|
|
861
869
|
image: usersInIam.image,
|
|
862
870
|
emailVerified: usersInIam.emailVerified,
|
|
863
871
|
phoneVerified: usersInIam.phoneVerified,
|
|
864
|
-
lastSignInAt: usersInIam.lastSignInAt
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
872
|
+
lastSignInAt: usersInIam.lastSignInAt,
|
|
873
|
+
userRoles: sql3`
|
|
874
|
+
COALESCE(
|
|
875
|
+
json_agg(
|
|
876
|
+
json_build_object(
|
|
877
|
+
'id', ${userRolesInIam.id},
|
|
878
|
+
'roleId', ${rolesInIam.id},
|
|
879
|
+
'code', ${rolesInIam.code},
|
|
880
|
+
'name', ${rolesInIam.name},
|
|
881
|
+
'description', ${rolesInIam.description}
|
|
882
|
+
)
|
|
883
|
+
) FILTER (WHERE ${userRolesInIam.id} IS NOT NULL),
|
|
884
|
+
'[]'::json
|
|
885
|
+
)
|
|
886
|
+
`
|
|
887
|
+
}).from(usersInIam).leftJoin(
|
|
888
|
+
userRolesInIam,
|
|
889
|
+
and6(
|
|
890
|
+
eq6(userRolesInIam.userId, usersInIam.id),
|
|
891
|
+
eq6(userRolesInIam.tenantId, tenantId)
|
|
869
892
|
)
|
|
870
|
-
).
|
|
893
|
+
).leftJoin(
|
|
894
|
+
rolesInIam,
|
|
895
|
+
and6(
|
|
896
|
+
eq6(userRolesInIam.roleId, rolesInIam.id),
|
|
897
|
+
eq6(rolesInIam.tenantId, tenantId)
|
|
898
|
+
)
|
|
899
|
+
).where(
|
|
900
|
+
and6(
|
|
901
|
+
eq6(usersInIam.tenantId, tenantId),
|
|
902
|
+
sql3`lower(${usersInIam.email}) = lower(${email})`
|
|
903
|
+
)
|
|
904
|
+
).groupBy(usersInIam.id).limit(1).then(([u]) => u || null);
|
|
905
|
+
return result;
|
|
871
906
|
};
|
|
872
907
|
|
|
873
908
|
// src/db/orm/iam/users/find-user-by-phone.ts
|
|
874
|
-
import { and as
|
|
875
|
-
var findUserByPhone = (db, tenantId, phone) => {
|
|
876
|
-
|
|
909
|
+
import { and as and7, eq as eq7, sql as sql4 } from "drizzle-orm";
|
|
910
|
+
var findUserByPhone = async (db, tenantId, phone) => {
|
|
911
|
+
const result = await db.select({
|
|
877
912
|
id: usersInIam.id,
|
|
878
913
|
tenantId: usersInIam.tenantId,
|
|
879
914
|
fullName: usersInIam.fullName,
|
|
@@ -883,8 +918,35 @@ var findUserByPhone = (db, tenantId, phone) => {
|
|
|
883
918
|
image: usersInIam.image,
|
|
884
919
|
emailVerified: usersInIam.emailVerified,
|
|
885
920
|
phoneVerified: usersInIam.phoneVerified,
|
|
886
|
-
lastSignInAt: usersInIam.lastSignInAt
|
|
887
|
-
|
|
921
|
+
lastSignInAt: usersInIam.lastSignInAt,
|
|
922
|
+
userRoles: sql4`
|
|
923
|
+
COALESCE(
|
|
924
|
+
json_agg(
|
|
925
|
+
json_build_object(
|
|
926
|
+
'id', ${userRolesInIam.id},
|
|
927
|
+
'roleId', ${rolesInIam.id},
|
|
928
|
+
'code', ${rolesInIam.code},
|
|
929
|
+
'name', ${rolesInIam.name},
|
|
930
|
+
'description', ${rolesInIam.description}
|
|
931
|
+
)
|
|
932
|
+
) FILTER (WHERE ${userRolesInIam.id} IS NOT NULL),
|
|
933
|
+
'[]'::json
|
|
934
|
+
)
|
|
935
|
+
`
|
|
936
|
+
}).from(usersInIam).leftJoin(
|
|
937
|
+
userRolesInIam,
|
|
938
|
+
and7(
|
|
939
|
+
eq7(userRolesInIam.userId, usersInIam.id),
|
|
940
|
+
eq7(userRolesInIam.tenantId, tenantId)
|
|
941
|
+
)
|
|
942
|
+
).leftJoin(
|
|
943
|
+
rolesInIam,
|
|
944
|
+
and7(
|
|
945
|
+
eq7(userRolesInIam.roleId, rolesInIam.id),
|
|
946
|
+
eq7(rolesInIam.tenantId, tenantId)
|
|
947
|
+
)
|
|
948
|
+
).where(and7(eq7(usersInIam.tenantId, tenantId), eq7(usersInIam.phone, phone))).groupBy(usersInIam.id).limit(1).then(([u]) => u || null);
|
|
949
|
+
return result;
|
|
888
950
|
};
|
|
889
951
|
|
|
890
952
|
// src/db/orm/iam/users/find-user-by-identifier.ts
|
|
@@ -939,22 +1001,22 @@ var insertSession = (db, data) => {
|
|
|
939
1001
|
};
|
|
940
1002
|
|
|
941
1003
|
// src/db/orm/iam/users/update-user-verified.ts
|
|
942
|
-
import { and as
|
|
1004
|
+
import { and as and8, eq as eq8 } from "drizzle-orm";
|
|
943
1005
|
var updateUserVerified = (db, tenantId, userId, type) => {
|
|
944
1006
|
return db.update(usersInIam).set({
|
|
945
1007
|
[type === "email" ? "emailVerified" : "phoneVerified"]: true,
|
|
946
1008
|
lastSignInAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
947
|
-
}).where(
|
|
1009
|
+
}).where(and8(eq8(usersInIam.id, userId), eq8(usersInIam.tenantId, tenantId)));
|
|
948
1010
|
};
|
|
949
1011
|
|
|
950
1012
|
// src/db/orm/iam/verifications/consume-verification.ts
|
|
951
|
-
import { eq as
|
|
1013
|
+
import { eq as eq9 } from "drizzle-orm";
|
|
952
1014
|
var consumeVerification = (db, verificationId) => {
|
|
953
|
-
return db.delete(verificationsInIam).where(
|
|
1015
|
+
return db.delete(verificationsInIam).where(eq9(verificationsInIam.id, verificationId));
|
|
954
1016
|
};
|
|
955
1017
|
|
|
956
1018
|
// src/db/orm/iam/verifications/find-verification-by-id.ts
|
|
957
|
-
import { eq as
|
|
1019
|
+
import { eq as eq10 } from "drizzle-orm";
|
|
958
1020
|
var findVerificationById = (db, verificationId) => {
|
|
959
1021
|
return db.select({
|
|
960
1022
|
id: verificationsInIam.id,
|
|
@@ -966,17 +1028,17 @@ var findVerificationById = (db, verificationId) => {
|
|
|
966
1028
|
expiresAt: verificationsInIam.expiresAt,
|
|
967
1029
|
createdAt: verificationsInIam.createdAt,
|
|
968
1030
|
attempt: verificationsInIam.attempt
|
|
969
|
-
}).from(verificationsInIam).where(
|
|
1031
|
+
}).from(verificationsInIam).where(eq10(verificationsInIam.id, verificationId)).limit(1).then(([verification]) => verification || null);
|
|
970
1032
|
};
|
|
971
1033
|
|
|
972
1034
|
// src/db/orm/iam/verifications/update-verification-attempt.ts
|
|
973
|
-
import { eq as
|
|
1035
|
+
import { eq as eq11 } from "drizzle-orm";
|
|
974
1036
|
var updateVerificationAttempt = async (db, verificationId) => {
|
|
975
1037
|
const verification = await findVerificationById(db, verificationId);
|
|
976
1038
|
if (!verification) {
|
|
977
1039
|
return;
|
|
978
1040
|
}
|
|
979
|
-
await db.update(verificationsInIam).set({ attempt: (verification.attempt || 0) + 1 }).where(
|
|
1041
|
+
await db.update(verificationsInIam).set({ attempt: (verification.attempt || 0) + 1 }).where(eq11(verificationsInIam.id, verificationId));
|
|
980
1042
|
};
|
|
981
1043
|
|
|
982
1044
|
// src/lib/session.ts
|
|
@@ -1089,7 +1151,7 @@ var emailVerificationConfirmHandler = async (c) => {
|
|
|
1089
1151
|
import { HTTPException as HTTPException4 } from "hono/http-exception";
|
|
1090
1152
|
|
|
1091
1153
|
// src/db/orm/iam/account-changes/cancel-pending-account-changes.ts
|
|
1092
|
-
import { and as
|
|
1154
|
+
import { and as and9, eq as eq12 } from "drizzle-orm";
|
|
1093
1155
|
var cancelPendingAccountChanges = (db, tenantId, userId, changeType) => {
|
|
1094
1156
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1095
1157
|
return db.update(accountChangesInIam).set({
|
|
@@ -1098,11 +1160,11 @@ var cancelPendingAccountChanges = (db, tenantId, userId, changeType) => {
|
|
|
1098
1160
|
updatedAt: now,
|
|
1099
1161
|
reason: "replaced"
|
|
1100
1162
|
}).where(
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1163
|
+
and9(
|
|
1164
|
+
eq12(accountChangesInIam.tenantId, tenantId),
|
|
1165
|
+
eq12(accountChangesInIam.userId, userId),
|
|
1166
|
+
eq12(accountChangesInIam.changeType, changeType),
|
|
1167
|
+
eq12(accountChangesInIam.status, "pending")
|
|
1106
1168
|
)
|
|
1107
1169
|
);
|
|
1108
1170
|
};
|
|
@@ -1125,13 +1187,13 @@ var insertPendingEmailChange = (db, data) => {
|
|
|
1125
1187
|
};
|
|
1126
1188
|
|
|
1127
1189
|
// src/db/orm/iam/verifications/delete-verifications-by-user-and-type.ts
|
|
1128
|
-
import { and as
|
|
1190
|
+
import { and as and10, eq as eq13 } from "drizzle-orm";
|
|
1129
1191
|
var deleteVerificationsByUserAndType = (db, tenantId, userId, type) => {
|
|
1130
1192
|
return db.delete(verificationsInIam).where(
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1193
|
+
and10(
|
|
1194
|
+
eq13(verificationsInIam.tenantId, tenantId),
|
|
1195
|
+
eq13(verificationsInIam.userId, userId),
|
|
1196
|
+
eq13(verificationsInIam.type, type)
|
|
1135
1197
|
)
|
|
1136
1198
|
);
|
|
1137
1199
|
};
|
|
@@ -1352,7 +1414,7 @@ import { getCookie } from "hono/cookie";
|
|
|
1352
1414
|
import { HTTPException as HTTPException6 } from "hono/http-exception";
|
|
1353
1415
|
|
|
1354
1416
|
// src/db/orm/iam/accounts/find-account-by-provider.ts
|
|
1355
|
-
import { and as
|
|
1417
|
+
import { and as and11, eq as eq14 } from "drizzle-orm";
|
|
1356
1418
|
var findAccountByProvider = (db, tenantId, userId, provider) => {
|
|
1357
1419
|
return db.select({
|
|
1358
1420
|
id: accountsInIam.id,
|
|
@@ -1362,34 +1424,34 @@ var findAccountByProvider = (db, tenantId, userId, provider) => {
|
|
|
1362
1424
|
providerAccountId: accountsInIam.providerAccountId,
|
|
1363
1425
|
password: accountsInIam.password
|
|
1364
1426
|
}).from(accountsInIam).where(
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1427
|
+
and11(
|
|
1428
|
+
eq14(accountsInIam.tenantId, tenantId),
|
|
1429
|
+
eq14(accountsInIam.userId, userId),
|
|
1430
|
+
eq14(accountsInIam.provider, provider)
|
|
1369
1431
|
)
|
|
1370
1432
|
).limit(1).then(([account]) => account || null);
|
|
1371
1433
|
};
|
|
1372
1434
|
|
|
1373
1435
|
// src/db/orm/iam/accounts/update-account-password.ts
|
|
1374
|
-
import { and as
|
|
1436
|
+
import { and as and12, eq as eq15 } from "drizzle-orm";
|
|
1375
1437
|
var updateAccountPassword = (db, tenantId, userId, password) => {
|
|
1376
1438
|
return db.update(accountsInIam).set({ password }).where(
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1439
|
+
and12(
|
|
1440
|
+
eq15(accountsInIam.tenantId, tenantId),
|
|
1441
|
+
eq15(accountsInIam.userId, userId),
|
|
1442
|
+
eq15(accountsInIam.provider, "credentials")
|
|
1381
1443
|
)
|
|
1382
1444
|
);
|
|
1383
1445
|
};
|
|
1384
1446
|
|
|
1385
1447
|
// src/db/orm/iam/sessions/delete-session-by-id.ts
|
|
1386
|
-
import { eq as
|
|
1448
|
+
import { eq as eq16 } from "drizzle-orm";
|
|
1387
1449
|
var deleteSessionById = (db, sessionId) => {
|
|
1388
|
-
return db.delete(sessionsInIam).where(
|
|
1450
|
+
return db.delete(sessionsInIam).where(eq16(sessionsInIam.id, sessionId));
|
|
1389
1451
|
};
|
|
1390
1452
|
|
|
1391
1453
|
// src/db/orm/iam/sessions/list-sessions-for-user.ts
|
|
1392
|
-
import { and as
|
|
1454
|
+
import { and as and13, asc, eq as eq17, gt as gt4 } from "drizzle-orm";
|
|
1393
1455
|
var listSessionsForUser = (db, tenantId, userId) => {
|
|
1394
1456
|
return db.select({
|
|
1395
1457
|
id: sessionsInIam.id,
|
|
@@ -1401,9 +1463,9 @@ var listSessionsForUser = (db, tenantId, userId) => {
|
|
|
1401
1463
|
userAgent: sessionsInIam.userAgent,
|
|
1402
1464
|
ip: sessionsInIam.ip
|
|
1403
1465
|
}).from(sessionsInIam).where(
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1466
|
+
and13(
|
|
1467
|
+
eq17(sessionsInIam.tenantId, tenantId),
|
|
1468
|
+
eq17(sessionsInIam.userId, userId),
|
|
1407
1469
|
gt4(sessionsInIam.expiresAt, (/* @__PURE__ */ new Date()).toISOString())
|
|
1408
1470
|
)
|
|
1409
1471
|
).orderBy(asc(sessionsInIam.createdAt)).then((sessions) => sessions);
|
|
@@ -1880,9 +1942,9 @@ var deleteOldestSessions = async (db, tenantId, userId, keepCount) => {
|
|
|
1880
1942
|
};
|
|
1881
1943
|
|
|
1882
1944
|
// src/db/orm/iam/users/update-last-sign-in.ts
|
|
1883
|
-
import { and as
|
|
1945
|
+
import { and as and14, eq as eq18 } from "drizzle-orm";
|
|
1884
1946
|
var updateLastSignIn = (db, tenantId, userId) => {
|
|
1885
|
-
return db.update(usersInIam).set({ lastSignInAt: (/* @__PURE__ */ new Date()).toISOString(), loginAttempt: 0 }).where(
|
|
1947
|
+
return db.update(usersInIam).set({ lastSignInAt: (/* @__PURE__ */ new Date()).toISOString(), loginAttempt: 0 }).where(and14(eq18(usersInIam.id, userId), eq18(usersInIam.tenantId, tenantId)));
|
|
1886
1948
|
};
|
|
1887
1949
|
|
|
1888
1950
|
// src/routes/handler/sign-in.ts
|
|
@@ -2035,7 +2097,7 @@ var insertCredentialsAccount = (db, data) => {
|
|
|
2035
2097
|
};
|
|
2036
2098
|
|
|
2037
2099
|
// src/db/orm/iam/users/find-user-by-handle.ts
|
|
2038
|
-
import { and as
|
|
2100
|
+
import { and as and15, eq as eq19, sql as sql5 } from "drizzle-orm";
|
|
2039
2101
|
var findUserByHandle = (db, tenantId, handle) => {
|
|
2040
2102
|
return db.select({
|
|
2041
2103
|
id: usersInIam.id,
|
|
@@ -2049,9 +2111,9 @@ var findUserByHandle = (db, tenantId, handle) => {
|
|
|
2049
2111
|
phoneVerified: usersInIam.phoneVerified,
|
|
2050
2112
|
lastSignInAt: usersInIam.lastSignInAt
|
|
2051
2113
|
}).from(usersInIam).where(
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2114
|
+
and15(
|
|
2115
|
+
eq19(usersInIam.tenantId, tenantId),
|
|
2116
|
+
sql5`lower(${usersInIam.handle}) = lower(${handle})`
|
|
2055
2117
|
)
|
|
2056
2118
|
).limit(1).then(([user]) => user || null);
|
|
2057
2119
|
};
|
|
@@ -2205,58 +2267,58 @@ var signUpHandler = async (c) => {
|
|
|
2205
2267
|
import { HTTPException as HTTPException13 } from "hono/http-exception";
|
|
2206
2268
|
|
|
2207
2269
|
// src/db/orm/iam/account-changes/mark-pending-account-change-applied.ts
|
|
2208
|
-
import { and as
|
|
2270
|
+
import { and as and16, eq as eq20 } from "drizzle-orm";
|
|
2209
2271
|
var markPendingAccountChangeApplied = (db, tenantId, userId, changeType, newValue) => {
|
|
2210
2272
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2211
|
-
const valueCondition = changeType === "email" ?
|
|
2273
|
+
const valueCondition = changeType === "email" ? eq20(accountChangesInIam.newEmail, newValue) : eq20(accountChangesInIam.newPhone, newValue);
|
|
2212
2274
|
return db.update(accountChangesInIam).set({
|
|
2213
2275
|
status: "applied",
|
|
2214
2276
|
confirmedAt: now,
|
|
2215
2277
|
updatedAt: now
|
|
2216
2278
|
}).where(
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2279
|
+
and16(
|
|
2280
|
+
eq20(accountChangesInIam.tenantId, tenantId),
|
|
2281
|
+
eq20(accountChangesInIam.userId, userId),
|
|
2282
|
+
eq20(accountChangesInIam.changeType, changeType),
|
|
2283
|
+
eq20(accountChangesInIam.status, "pending"),
|
|
2222
2284
|
valueCondition
|
|
2223
2285
|
)
|
|
2224
2286
|
);
|
|
2225
2287
|
};
|
|
2226
2288
|
|
|
2227
2289
|
// src/db/orm/iam/accounts/update-credentials-provider-account-id.ts
|
|
2228
|
-
import { and as
|
|
2290
|
+
import { and as and17, eq as eq21 } from "drizzle-orm";
|
|
2229
2291
|
var updateCredentialsProviderAccountId = async (db, tenantId, userId, providerAccountId) => {
|
|
2230
2292
|
const updated = await db.update(accountsInIam).set({ providerAccountId }).where(
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2293
|
+
and17(
|
|
2294
|
+
eq21(accountsInIam.tenantId, tenantId),
|
|
2295
|
+
eq21(accountsInIam.userId, userId),
|
|
2296
|
+
eq21(accountsInIam.provider, "credentials")
|
|
2235
2297
|
)
|
|
2236
2298
|
).returning({ id: accountsInIam.id }).then(([row]) => row?.id);
|
|
2237
2299
|
return Boolean(updated);
|
|
2238
2300
|
};
|
|
2239
2301
|
|
|
2240
2302
|
// src/db/orm/iam/sessions/delete-other-sessions.ts
|
|
2241
|
-
import { and as
|
|
2303
|
+
import { and as and18, eq as eq22, ne } from "drizzle-orm";
|
|
2242
2304
|
var deleteOtherSessions = (db, tenantId, userId, currentSessionId) => {
|
|
2243
2305
|
return db.delete(sessionsInIam).where(
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2306
|
+
and18(
|
|
2307
|
+
eq22(sessionsInIam.tenantId, tenantId),
|
|
2308
|
+
eq22(sessionsInIam.userId, userId),
|
|
2247
2309
|
ne(sessionsInIam.id, currentSessionId)
|
|
2248
2310
|
)
|
|
2249
2311
|
);
|
|
2250
2312
|
};
|
|
2251
2313
|
|
|
2252
2314
|
// src/db/orm/iam/users/update-user-email.ts
|
|
2253
|
-
import { and as
|
|
2315
|
+
import { and as and19, eq as eq23, sql as sql6 } from "drizzle-orm";
|
|
2254
2316
|
var updateUserEmail = (db, tenantId, userId, email) => {
|
|
2255
2317
|
return db.update(usersInIam).set({
|
|
2256
2318
|
email,
|
|
2257
2319
|
emailVerified: true,
|
|
2258
|
-
updatedAt:
|
|
2259
|
-
}).where(
|
|
2320
|
+
updatedAt: sql6`CURRENT_TIMESTAMP`
|
|
2321
|
+
}).where(and19(eq23(usersInIam.id, userId), eq23(usersInIam.tenantId, tenantId))).returning({
|
|
2260
2322
|
id: usersInIam.id,
|
|
2261
2323
|
tenantId: usersInIam.tenantId,
|
|
2262
2324
|
fullName: usersInIam.fullName,
|
|
@@ -2313,13 +2375,13 @@ var updateEmailHandler = async (c) => {
|
|
|
2313
2375
|
import { HTTPException as HTTPException14 } from "hono/http-exception";
|
|
2314
2376
|
|
|
2315
2377
|
// src/db/orm/iam/users/update-user-phone.ts
|
|
2316
|
-
import { and as
|
|
2378
|
+
import { and as and20, eq as eq24, sql as sql7 } from "drizzle-orm";
|
|
2317
2379
|
var updateUserPhone = (db, tenantId, userId, phone) => {
|
|
2318
2380
|
return db.update(usersInIam).set({
|
|
2319
2381
|
phone,
|
|
2320
2382
|
phoneVerified: true,
|
|
2321
|
-
updatedAt:
|
|
2322
|
-
}).where(
|
|
2383
|
+
updatedAt: sql7`CURRENT_TIMESTAMP`
|
|
2384
|
+
}).where(and20(eq24(usersInIam.id, userId), eq24(usersInIam.tenantId, tenantId))).returning({
|
|
2323
2385
|
id: usersInIam.id,
|
|
2324
2386
|
tenantId: usersInIam.tenantId,
|
|
2325
2387
|
fullName: usersInIam.fullName,
|
|
@@ -2376,7 +2438,7 @@ var updatePhoneHandler = async (c) => {
|
|
|
2376
2438
|
import { HTTPException as HTTPException15 } from "hono/http-exception";
|
|
2377
2439
|
|
|
2378
2440
|
// src/db/orm/iam/users/update-user-profile.ts
|
|
2379
|
-
import { and as
|
|
2441
|
+
import { and as and21, eq as eq25, sql as sql8 } from "drizzle-orm";
|
|
2380
2442
|
var updateUserProfile = async (db, tenantId, userId, data) => {
|
|
2381
2443
|
const updateData = {};
|
|
2382
2444
|
if (data.fullName !== void 0) {
|
|
@@ -2384,8 +2446,8 @@ var updateUserProfile = async (db, tenantId, userId, data) => {
|
|
|
2384
2446
|
}
|
|
2385
2447
|
return await db.update(usersInIam).set({
|
|
2386
2448
|
...updateData,
|
|
2387
|
-
updatedAt:
|
|
2388
|
-
}).where(
|
|
2449
|
+
updatedAt: sql8`CURRENT_TIMESTAMP`
|
|
2450
|
+
}).where(and21(eq25(usersInIam.id, userId), eq25(usersInIam.tenantId, tenantId))).returning({
|
|
2389
2451
|
id: usersInIam.id,
|
|
2390
2452
|
tenantId: usersInIam.tenantId,
|
|
2391
2453
|
fullName: usersInIam.fullName,
|
|
@@ -2952,14 +3014,9 @@ var createAuthMiddleware = (config, database, getTenantId) => {
|
|
|
2952
3014
|
session.userId
|
|
2953
3015
|
);
|
|
2954
3016
|
if (user) {
|
|
2955
|
-
const userRoles = await findUserRoles(
|
|
2956
|
-
database,
|
|
2957
|
-
session.tenantId,
|
|
2958
|
-
session.userId
|
|
2959
|
-
);
|
|
2960
3017
|
c.set("tenantId", enableTenant ? session.tenantId : tenantId);
|
|
2961
3018
|
c.set("userId", user.id);
|
|
2962
|
-
c.set("user",
|
|
3019
|
+
c.set("user", user);
|
|
2963
3020
|
c.set("session", session);
|
|
2964
3021
|
}
|
|
2965
3022
|
}
|