@mesob/auth-hono 0.0.5 → 0.0.7

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.
@@ -1,3 +1,10 @@
1
+ type UserRole = {
2
+ id: string;
3
+ roleId: string;
4
+ code: string;
5
+ name: unknown;
6
+ description: unknown;
7
+ };
1
8
  type User = {
2
9
  id: string;
3
10
  tenantId: string;
@@ -9,6 +16,7 @@ type User = {
9
16
  emailVerified: boolean;
10
17
  phoneVerified: boolean;
11
18
  lastSignInAt: string | null;
19
+ userRoles?: UserRole[];
12
20
  };
13
21
  type Session = {
14
22
  id: string;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { OpenAPIHono } from '@hono/zod-openapi';
2
- import { A as AuthConfig, S as Session, U as User } from './index-BzGjOP5Z.js';
2
+ import { A as AuthConfig, S as Session, U as User } from './index-J2ZbOnZO.js';
3
3
 
4
4
  declare const createAuthHandler: (config: AuthConfig) => OpenAPIHono<any, {}, "/">;
5
5
  declare const createAuthRoutes: (config: AuthConfig) => OpenAPIHono<any, {}, "/">;
package/dist/index.js CHANGED
@@ -470,6 +470,24 @@ import { OpenAPIHono as OpenAPIHono2 } from "@hono/zod-openapi";
470
470
  import { getCookie as getCookie3 } from "hono/cookie";
471
471
  import { HTTPException as HTTPException16 } from "hono/http-exception";
472
472
 
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
+
473
491
  // src/lib/crypto.ts
474
492
  import { scrypt } from "@noble/hashes/scrypt.js";
475
493
  import { randomBytes } from "@noble/hashes/utils.js";
@@ -558,6 +576,13 @@ import { z } from "zod";
558
576
  var emailField = z.string().trim().email("Invalid email address").max(255, "Email too long");
559
577
  var phoneField = z.string().trim().min(6, "Phone too short").max(30, "Phone too long").regex(/^[+()\d\s-]+$/, "Invalid phone number format");
560
578
  var passwordField = z.string().min(8, "Password must be at least 8 characters").max(128, "Password too long");
579
+ var userRoleSchema = z.object({
580
+ id: z.string().uuid(),
581
+ roleId: z.string().uuid(),
582
+ code: z.string(),
583
+ name: z.string(),
584
+ description: z.string()
585
+ });
561
586
  var userSchema = z.object({
562
587
  id: z.string().uuid(),
563
588
  tenantId: z.string(),
@@ -568,7 +593,8 @@ var userSchema = z.object({
568
593
  image: z.string().nullable(),
569
594
  emailVerified: z.boolean(),
570
595
  phoneVerified: z.boolean(),
571
- lastSignInAt: z.string().datetime().nullable()
596
+ lastSignInAt: z.string().datetime().nullable(),
597
+ userRoles: z.array(userRoleSchema).nullable()
572
598
  });
573
599
  var sessionSchema = z.object({
574
600
  id: z.string().uuid(),
@@ -682,24 +708,24 @@ var pendingAccountChangeResponseSchema = z.object({
682
708
  import { HTTPException as HTTPException2 } from "hono/http-exception";
683
709
 
684
710
  // src/db/orm/iam/account-changes/expire-pending-account-changes.ts
685
- import { and as and3, eq as eq3, lte } from "drizzle-orm";
711
+ import { and as and4, eq as eq4, lte } from "drizzle-orm";
686
712
  var expirePendingAccountChanges = (db, tenantId, userId) => {
687
713
  const now = (/* @__PURE__ */ new Date()).toISOString();
688
714
  return db.update(accountChangesInIam).set({
689
715
  status: "expired",
690
716
  updatedAt: now
691
717
  }).where(
692
- and3(
693
- eq3(accountChangesInIam.tenantId, tenantId),
694
- eq3(accountChangesInIam.userId, userId),
695
- eq3(accountChangesInIam.status, "pending"),
718
+ and4(
719
+ eq4(accountChangesInIam.tenantId, tenantId),
720
+ eq4(accountChangesInIam.userId, userId),
721
+ eq4(accountChangesInIam.status, "pending"),
696
722
  lte(accountChangesInIam.expiresAt, now)
697
723
  )
698
724
  );
699
725
  };
700
726
 
701
727
  // src/db/orm/iam/account-changes/find-pending-account-change.ts
702
- import { and as and4, desc, eq as eq4, gt as gt2 } from "drizzle-orm";
728
+ import { and as and5, desc, eq as eq5, gt as gt2 } from "drizzle-orm";
703
729
  var findPendingAccountChange = async (db, tenantId, userId) => {
704
730
  const now = (/* @__PURE__ */ new Date()).toISOString();
705
731
  return await db.select({
@@ -708,10 +734,10 @@ var findPendingAccountChange = async (db, tenantId, userId) => {
708
734
  newPhone: accountChangesInIam.newPhone,
709
735
  expiresAt: accountChangesInIam.expiresAt
710
736
  }).from(accountChangesInIam).where(
711
- and4(
712
- eq4(accountChangesInIam.tenantId, tenantId),
713
- eq4(accountChangesInIam.userId, userId),
714
- eq4(accountChangesInIam.status, "pending"),
737
+ and5(
738
+ eq5(accountChangesInIam.tenantId, tenantId),
739
+ eq5(accountChangesInIam.userId, userId),
740
+ eq5(accountChangesInIam.status, "pending"),
715
741
  gt2(accountChangesInIam.expiresAt, now)
716
742
  )
717
743
  ).orderBy(desc(accountChangesInIam.createdAt)).limit(1).then(([row]) => {
@@ -731,18 +757,18 @@ var findPendingAccountChange = async (db, tenantId, userId) => {
731
757
  };
732
758
 
733
759
  // src/db/orm/iam/verifications/find-active-verification-id.ts
734
- import { and as and5, desc as desc2, eq as eq5, gt as gt3 } from "drizzle-orm";
760
+ import { and as and6, desc as desc2, eq as eq6, gt as gt3 } from "drizzle-orm";
735
761
  var findActiveVerificationId = async (db, tenantId, userId, type, to) => {
736
762
  const now = (/* @__PURE__ */ new Date()).toISOString();
737
763
  return await db.select({
738
764
  verificationId: verificationsInIam.id,
739
765
  expiresAt: verificationsInIam.expiresAt
740
766
  }).from(verificationsInIam).where(
741
- and5(
742
- eq5(verificationsInIam.tenantId, tenantId),
743
- eq5(verificationsInIam.userId, userId),
744
- eq5(verificationsInIam.type, type),
745
- eq5(verificationsInIam.to, to),
767
+ and6(
768
+ eq6(verificationsInIam.tenantId, tenantId),
769
+ eq6(verificationsInIam.userId, userId),
770
+ eq6(verificationsInIam.type, type),
771
+ eq6(verificationsInIam.to, to),
746
772
  gt3(verificationsInIam.expiresAt, now)
747
773
  )
748
774
  ).orderBy(desc2(verificationsInIam.createdAt)).limit(1).then(([row]) => row ? row : null);
@@ -823,7 +849,7 @@ var accountChangePendingHandler = async (c) => {
823
849
  };
824
850
 
825
851
  // src/db/orm/iam/users/find-user-by-email.ts
826
- import { and as and6, eq as eq6, sql as sql2 } from "drizzle-orm";
852
+ import { and as and7, eq as eq7, sql as sql2 } from "drizzle-orm";
827
853
  var findUserByEmail = (db, tenantId, email) => {
828
854
  return db.select({
829
855
  id: usersInIam.id,
@@ -837,15 +863,15 @@ var findUserByEmail = (db, tenantId, email) => {
837
863
  phoneVerified: usersInIam.phoneVerified,
838
864
  lastSignInAt: usersInIam.lastSignInAt
839
865
  }).from(usersInIam).where(
840
- and6(
841
- eq6(usersInIam.tenantId, tenantId),
866
+ and7(
867
+ eq7(usersInIam.tenantId, tenantId),
842
868
  sql2`lower(${usersInIam.email}) = lower(${email})`
843
869
  )
844
870
  ).limit(1).then(([user]) => user || null);
845
871
  };
846
872
 
847
873
  // src/db/orm/iam/users/find-user-by-phone.ts
848
- import { and as and7, eq as eq7 } from "drizzle-orm";
874
+ import { and as and8, eq as eq8 } from "drizzle-orm";
849
875
  var findUserByPhone = (db, tenantId, phone) => {
850
876
  return db.select({
851
877
  id: usersInIam.id,
@@ -858,7 +884,7 @@ var findUserByPhone = (db, tenantId, phone) => {
858
884
  emailVerified: usersInIam.emailVerified,
859
885
  phoneVerified: usersInIam.phoneVerified,
860
886
  lastSignInAt: usersInIam.lastSignInAt
861
- }).from(usersInIam).where(and7(eq7(usersInIam.tenantId, tenantId), eq7(usersInIam.phone, phone))).limit(1).then(([user]) => user || null);
887
+ }).from(usersInIam).where(and8(eq8(usersInIam.tenantId, tenantId), eq8(usersInIam.phone, phone))).limit(1).then(([user]) => user || null);
862
888
  };
863
889
 
864
890
  // src/db/orm/iam/users/find-user-by-identifier.ts
@@ -913,22 +939,22 @@ var insertSession = (db, data) => {
913
939
  };
914
940
 
915
941
  // src/db/orm/iam/users/update-user-verified.ts
916
- import { and as and8, eq as eq8 } from "drizzle-orm";
942
+ import { and as and9, eq as eq9 } from "drizzle-orm";
917
943
  var updateUserVerified = (db, tenantId, userId, type) => {
918
944
  return db.update(usersInIam).set({
919
945
  [type === "email" ? "emailVerified" : "phoneVerified"]: true,
920
946
  lastSignInAt: (/* @__PURE__ */ new Date()).toISOString()
921
- }).where(and8(eq8(usersInIam.id, userId), eq8(usersInIam.tenantId, tenantId)));
947
+ }).where(and9(eq9(usersInIam.id, userId), eq9(usersInIam.tenantId, tenantId)));
922
948
  };
923
949
 
924
950
  // src/db/orm/iam/verifications/consume-verification.ts
925
- import { eq as eq9 } from "drizzle-orm";
951
+ import { eq as eq10 } from "drizzle-orm";
926
952
  var consumeVerification = (db, verificationId) => {
927
- return db.delete(verificationsInIam).where(eq9(verificationsInIam.id, verificationId));
953
+ return db.delete(verificationsInIam).where(eq10(verificationsInIam.id, verificationId));
928
954
  };
929
955
 
930
956
  // src/db/orm/iam/verifications/find-verification-by-id.ts
931
- import { eq as eq10 } from "drizzle-orm";
957
+ import { eq as eq11 } from "drizzle-orm";
932
958
  var findVerificationById = (db, verificationId) => {
933
959
  return db.select({
934
960
  id: verificationsInIam.id,
@@ -940,17 +966,17 @@ var findVerificationById = (db, verificationId) => {
940
966
  expiresAt: verificationsInIam.expiresAt,
941
967
  createdAt: verificationsInIam.createdAt,
942
968
  attempt: verificationsInIam.attempt
943
- }).from(verificationsInIam).where(eq10(verificationsInIam.id, verificationId)).limit(1).then(([verification]) => verification || null);
969
+ }).from(verificationsInIam).where(eq11(verificationsInIam.id, verificationId)).limit(1).then(([verification]) => verification || null);
944
970
  };
945
971
 
946
972
  // src/db/orm/iam/verifications/update-verification-attempt.ts
947
- import { eq as eq11 } from "drizzle-orm";
973
+ import { eq as eq12 } from "drizzle-orm";
948
974
  var updateVerificationAttempt = async (db, verificationId) => {
949
975
  const verification = await findVerificationById(db, verificationId);
950
976
  if (!verification) {
951
977
  return;
952
978
  }
953
- await db.update(verificationsInIam).set({ attempt: (verification.attempt || 0) + 1 }).where(eq11(verificationsInIam.id, verificationId));
979
+ await db.update(verificationsInIam).set({ attempt: (verification.attempt || 0) + 1 }).where(eq12(verificationsInIam.id, verificationId));
954
980
  };
955
981
 
956
982
  // src/lib/session.ts
@@ -1063,7 +1089,7 @@ var emailVerificationConfirmHandler = async (c) => {
1063
1089
  import { HTTPException as HTTPException4 } from "hono/http-exception";
1064
1090
 
1065
1091
  // src/db/orm/iam/account-changes/cancel-pending-account-changes.ts
1066
- import { and as and9, eq as eq12 } from "drizzle-orm";
1092
+ import { and as and10, eq as eq13 } from "drizzle-orm";
1067
1093
  var cancelPendingAccountChanges = (db, tenantId, userId, changeType) => {
1068
1094
  const now = (/* @__PURE__ */ new Date()).toISOString();
1069
1095
  return db.update(accountChangesInIam).set({
@@ -1072,11 +1098,11 @@ var cancelPendingAccountChanges = (db, tenantId, userId, changeType) => {
1072
1098
  updatedAt: now,
1073
1099
  reason: "replaced"
1074
1100
  }).where(
1075
- and9(
1076
- eq12(accountChangesInIam.tenantId, tenantId),
1077
- eq12(accountChangesInIam.userId, userId),
1078
- eq12(accountChangesInIam.changeType, changeType),
1079
- eq12(accountChangesInIam.status, "pending")
1101
+ and10(
1102
+ eq13(accountChangesInIam.tenantId, tenantId),
1103
+ eq13(accountChangesInIam.userId, userId),
1104
+ eq13(accountChangesInIam.changeType, changeType),
1105
+ eq13(accountChangesInIam.status, "pending")
1080
1106
  )
1081
1107
  );
1082
1108
  };
@@ -1099,13 +1125,13 @@ var insertPendingEmailChange = (db, data) => {
1099
1125
  };
1100
1126
 
1101
1127
  // src/db/orm/iam/verifications/delete-verifications-by-user-and-type.ts
1102
- import { and as and10, eq as eq13 } from "drizzle-orm";
1128
+ import { and as and11, eq as eq14 } from "drizzle-orm";
1103
1129
  var deleteVerificationsByUserAndType = (db, tenantId, userId, type) => {
1104
1130
  return db.delete(verificationsInIam).where(
1105
- and10(
1106
- eq13(verificationsInIam.tenantId, tenantId),
1107
- eq13(verificationsInIam.userId, userId),
1108
- eq13(verificationsInIam.type, type)
1131
+ and11(
1132
+ eq14(verificationsInIam.tenantId, tenantId),
1133
+ eq14(verificationsInIam.userId, userId),
1134
+ eq14(verificationsInIam.type, type)
1109
1135
  )
1110
1136
  );
1111
1137
  };
@@ -1326,7 +1352,7 @@ import { getCookie } from "hono/cookie";
1326
1352
  import { HTTPException as HTTPException6 } from "hono/http-exception";
1327
1353
 
1328
1354
  // src/db/orm/iam/accounts/find-account-by-provider.ts
1329
- import { and as and11, eq as eq14 } from "drizzle-orm";
1355
+ import { and as and12, eq as eq15 } from "drizzle-orm";
1330
1356
  var findAccountByProvider = (db, tenantId, userId, provider) => {
1331
1357
  return db.select({
1332
1358
  id: accountsInIam.id,
@@ -1336,34 +1362,34 @@ var findAccountByProvider = (db, tenantId, userId, provider) => {
1336
1362
  providerAccountId: accountsInIam.providerAccountId,
1337
1363
  password: accountsInIam.password
1338
1364
  }).from(accountsInIam).where(
1339
- and11(
1340
- eq14(accountsInIam.tenantId, tenantId),
1341
- eq14(accountsInIam.userId, userId),
1342
- eq14(accountsInIam.provider, provider)
1365
+ and12(
1366
+ eq15(accountsInIam.tenantId, tenantId),
1367
+ eq15(accountsInIam.userId, userId),
1368
+ eq15(accountsInIam.provider, provider)
1343
1369
  )
1344
1370
  ).limit(1).then(([account]) => account || null);
1345
1371
  };
1346
1372
 
1347
1373
  // src/db/orm/iam/accounts/update-account-password.ts
1348
- import { and as and12, eq as eq15 } from "drizzle-orm";
1374
+ import { and as and13, eq as eq16 } from "drizzle-orm";
1349
1375
  var updateAccountPassword = (db, tenantId, userId, password) => {
1350
1376
  return db.update(accountsInIam).set({ password }).where(
1351
- and12(
1352
- eq15(accountsInIam.tenantId, tenantId),
1353
- eq15(accountsInIam.userId, userId),
1354
- eq15(accountsInIam.provider, "credentials")
1377
+ and13(
1378
+ eq16(accountsInIam.tenantId, tenantId),
1379
+ eq16(accountsInIam.userId, userId),
1380
+ eq16(accountsInIam.provider, "credentials")
1355
1381
  )
1356
1382
  );
1357
1383
  };
1358
1384
 
1359
1385
  // src/db/orm/iam/sessions/delete-session-by-id.ts
1360
- import { eq as eq16 } from "drizzle-orm";
1386
+ import { eq as eq17 } from "drizzle-orm";
1361
1387
  var deleteSessionById = (db, sessionId) => {
1362
- return db.delete(sessionsInIam).where(eq16(sessionsInIam.id, sessionId));
1388
+ return db.delete(sessionsInIam).where(eq17(sessionsInIam.id, sessionId));
1363
1389
  };
1364
1390
 
1365
1391
  // src/db/orm/iam/sessions/list-sessions-for-user.ts
1366
- import { and as and13, asc, eq as eq17, gt as gt4 } from "drizzle-orm";
1392
+ import { and as and14, asc, eq as eq18, gt as gt4 } from "drizzle-orm";
1367
1393
  var listSessionsForUser = (db, tenantId, userId) => {
1368
1394
  return db.select({
1369
1395
  id: sessionsInIam.id,
@@ -1375,9 +1401,9 @@ var listSessionsForUser = (db, tenantId, userId) => {
1375
1401
  userAgent: sessionsInIam.userAgent,
1376
1402
  ip: sessionsInIam.ip
1377
1403
  }).from(sessionsInIam).where(
1378
- and13(
1379
- eq17(sessionsInIam.tenantId, tenantId),
1380
- eq17(sessionsInIam.userId, userId),
1404
+ and14(
1405
+ eq18(sessionsInIam.tenantId, tenantId),
1406
+ eq18(sessionsInIam.userId, userId),
1381
1407
  gt4(sessionsInIam.expiresAt, (/* @__PURE__ */ new Date()).toISOString())
1382
1408
  )
1383
1409
  ).orderBy(asc(sessionsInIam.createdAt)).then((sessions) => sessions);
@@ -1854,9 +1880,9 @@ var deleteOldestSessions = async (db, tenantId, userId, keepCount) => {
1854
1880
  };
1855
1881
 
1856
1882
  // src/db/orm/iam/users/update-last-sign-in.ts
1857
- import { and as and14, eq as eq18 } from "drizzle-orm";
1883
+ import { and as and15, eq as eq19 } from "drizzle-orm";
1858
1884
  var updateLastSignIn = (db, tenantId, userId) => {
1859
- return db.update(usersInIam).set({ lastSignInAt: (/* @__PURE__ */ new Date()).toISOString(), loginAttempt: 0 }).where(and14(eq18(usersInIam.id, userId), eq18(usersInIam.tenantId, tenantId)));
1885
+ return db.update(usersInIam).set({ lastSignInAt: (/* @__PURE__ */ new Date()).toISOString(), loginAttempt: 0 }).where(and15(eq19(usersInIam.id, userId), eq19(usersInIam.tenantId, tenantId)));
1860
1886
  };
1861
1887
 
1862
1888
  // src/routes/handler/sign-in.ts
@@ -2009,7 +2035,7 @@ var insertCredentialsAccount = (db, data) => {
2009
2035
  };
2010
2036
 
2011
2037
  // src/db/orm/iam/users/find-user-by-handle.ts
2012
- import { and as and15, eq as eq19, sql as sql3 } from "drizzle-orm";
2038
+ import { and as and16, eq as eq20, sql as sql3 } from "drizzle-orm";
2013
2039
  var findUserByHandle = (db, tenantId, handle) => {
2014
2040
  return db.select({
2015
2041
  id: usersInIam.id,
@@ -2023,8 +2049,8 @@ var findUserByHandle = (db, tenantId, handle) => {
2023
2049
  phoneVerified: usersInIam.phoneVerified,
2024
2050
  lastSignInAt: usersInIam.lastSignInAt
2025
2051
  }).from(usersInIam).where(
2026
- and15(
2027
- eq19(usersInIam.tenantId, tenantId),
2052
+ and16(
2053
+ eq20(usersInIam.tenantId, tenantId),
2028
2054
  sql3`lower(${usersInIam.handle}) = lower(${handle})`
2029
2055
  )
2030
2056
  ).limit(1).then(([user]) => user || null);
@@ -2179,58 +2205,58 @@ var signUpHandler = async (c) => {
2179
2205
  import { HTTPException as HTTPException13 } from "hono/http-exception";
2180
2206
 
2181
2207
  // src/db/orm/iam/account-changes/mark-pending-account-change-applied.ts
2182
- import { and as and16, eq as eq20 } from "drizzle-orm";
2208
+ import { and as and17, eq as eq21 } from "drizzle-orm";
2183
2209
  var markPendingAccountChangeApplied = (db, tenantId, userId, changeType, newValue) => {
2184
2210
  const now = (/* @__PURE__ */ new Date()).toISOString();
2185
- const valueCondition = changeType === "email" ? eq20(accountChangesInIam.newEmail, newValue) : eq20(accountChangesInIam.newPhone, newValue);
2211
+ const valueCondition = changeType === "email" ? eq21(accountChangesInIam.newEmail, newValue) : eq21(accountChangesInIam.newPhone, newValue);
2186
2212
  return db.update(accountChangesInIam).set({
2187
2213
  status: "applied",
2188
2214
  confirmedAt: now,
2189
2215
  updatedAt: now
2190
2216
  }).where(
2191
- and16(
2192
- eq20(accountChangesInIam.tenantId, tenantId),
2193
- eq20(accountChangesInIam.userId, userId),
2194
- eq20(accountChangesInIam.changeType, changeType),
2195
- eq20(accountChangesInIam.status, "pending"),
2217
+ and17(
2218
+ eq21(accountChangesInIam.tenantId, tenantId),
2219
+ eq21(accountChangesInIam.userId, userId),
2220
+ eq21(accountChangesInIam.changeType, changeType),
2221
+ eq21(accountChangesInIam.status, "pending"),
2196
2222
  valueCondition
2197
2223
  )
2198
2224
  );
2199
2225
  };
2200
2226
 
2201
2227
  // src/db/orm/iam/accounts/update-credentials-provider-account-id.ts
2202
- import { and as and17, eq as eq21 } from "drizzle-orm";
2228
+ import { and as and18, eq as eq22 } from "drizzle-orm";
2203
2229
  var updateCredentialsProviderAccountId = async (db, tenantId, userId, providerAccountId) => {
2204
2230
  const updated = await db.update(accountsInIam).set({ providerAccountId }).where(
2205
- and17(
2206
- eq21(accountsInIam.tenantId, tenantId),
2207
- eq21(accountsInIam.userId, userId),
2208
- eq21(accountsInIam.provider, "credentials")
2231
+ and18(
2232
+ eq22(accountsInIam.tenantId, tenantId),
2233
+ eq22(accountsInIam.userId, userId),
2234
+ eq22(accountsInIam.provider, "credentials")
2209
2235
  )
2210
2236
  ).returning({ id: accountsInIam.id }).then(([row]) => row?.id);
2211
2237
  return Boolean(updated);
2212
2238
  };
2213
2239
 
2214
2240
  // src/db/orm/iam/sessions/delete-other-sessions.ts
2215
- import { and as and18, eq as eq22, ne } from "drizzle-orm";
2241
+ import { and as and19, eq as eq23, ne } from "drizzle-orm";
2216
2242
  var deleteOtherSessions = (db, tenantId, userId, currentSessionId) => {
2217
2243
  return db.delete(sessionsInIam).where(
2218
- and18(
2219
- eq22(sessionsInIam.tenantId, tenantId),
2220
- eq22(sessionsInIam.userId, userId),
2244
+ and19(
2245
+ eq23(sessionsInIam.tenantId, tenantId),
2246
+ eq23(sessionsInIam.userId, userId),
2221
2247
  ne(sessionsInIam.id, currentSessionId)
2222
2248
  )
2223
2249
  );
2224
2250
  };
2225
2251
 
2226
2252
  // src/db/orm/iam/users/update-user-email.ts
2227
- import { and as and19, eq as eq23, sql as sql4 } from "drizzle-orm";
2253
+ import { and as and20, eq as eq24, sql as sql4 } from "drizzle-orm";
2228
2254
  var updateUserEmail = (db, tenantId, userId, email) => {
2229
2255
  return db.update(usersInIam).set({
2230
2256
  email,
2231
2257
  emailVerified: true,
2232
2258
  updatedAt: sql4`CURRENT_TIMESTAMP`
2233
- }).where(and19(eq23(usersInIam.id, userId), eq23(usersInIam.tenantId, tenantId))).returning({
2259
+ }).where(and20(eq24(usersInIam.id, userId), eq24(usersInIam.tenantId, tenantId))).returning({
2234
2260
  id: usersInIam.id,
2235
2261
  tenantId: usersInIam.tenantId,
2236
2262
  fullName: usersInIam.fullName,
@@ -2287,13 +2313,13 @@ var updateEmailHandler = async (c) => {
2287
2313
  import { HTTPException as HTTPException14 } from "hono/http-exception";
2288
2314
 
2289
2315
  // src/db/orm/iam/users/update-user-phone.ts
2290
- import { and as and20, eq as eq24, sql as sql5 } from "drizzle-orm";
2316
+ import { and as and21, eq as eq25, sql as sql5 } from "drizzle-orm";
2291
2317
  var updateUserPhone = (db, tenantId, userId, phone) => {
2292
2318
  return db.update(usersInIam).set({
2293
2319
  phone,
2294
2320
  phoneVerified: true,
2295
2321
  updatedAt: sql5`CURRENT_TIMESTAMP`
2296
- }).where(and20(eq24(usersInIam.id, userId), eq24(usersInIam.tenantId, tenantId))).returning({
2322
+ }).where(and21(eq25(usersInIam.id, userId), eq25(usersInIam.tenantId, tenantId))).returning({
2297
2323
  id: usersInIam.id,
2298
2324
  tenantId: usersInIam.tenantId,
2299
2325
  fullName: usersInIam.fullName,
@@ -2350,7 +2376,7 @@ var updatePhoneHandler = async (c) => {
2350
2376
  import { HTTPException as HTTPException15 } from "hono/http-exception";
2351
2377
 
2352
2378
  // src/db/orm/iam/users/update-user-profile.ts
2353
- import { and as and21, eq as eq25, sql as sql6 } from "drizzle-orm";
2379
+ import { and as and22, eq as eq26, sql as sql6 } from "drizzle-orm";
2354
2380
  var updateUserProfile = async (db, tenantId, userId, data) => {
2355
2381
  const updateData = {};
2356
2382
  if (data.fullName !== void 0) {
@@ -2359,7 +2385,7 @@ var updateUserProfile = async (db, tenantId, userId, data) => {
2359
2385
  return await db.update(usersInIam).set({
2360
2386
  ...updateData,
2361
2387
  updatedAt: sql6`CURRENT_TIMESTAMP`
2362
- }).where(and21(eq25(usersInIam.id, userId), eq25(usersInIam.tenantId, tenantId))).returning({
2388
+ }).where(and22(eq26(usersInIam.id, userId), eq26(usersInIam.tenantId, tenantId))).returning({
2363
2389
  id: usersInIam.id,
2364
2390
  tenantId: usersInIam.tenantId,
2365
2391
  fullName: usersInIam.fullName,
@@ -2926,9 +2952,14 @@ var createAuthMiddleware = (config, database, getTenantId) => {
2926
2952
  session.userId
2927
2953
  );
2928
2954
  if (user) {
2955
+ const userRoles = await findUserRoles(
2956
+ database,
2957
+ session.tenantId,
2958
+ session.userId
2959
+ );
2929
2960
  c.set("tenantId", enableTenant ? session.tenantId : tenantId);
2930
2961
  c.set("userId", user.id);
2931
- c.set("user", user);
2962
+ c.set("user", { ...user, userRoles: userRoles || [] });
2932
2963
  c.set("session", session);
2933
2964
  }
2934
2965
  }