@mesob/auth-hono 0.0.5 → 0.0.6

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";
@@ -682,24 +700,24 @@ var pendingAccountChangeResponseSchema = z.object({
682
700
  import { HTTPException as HTTPException2 } from "hono/http-exception";
683
701
 
684
702
  // src/db/orm/iam/account-changes/expire-pending-account-changes.ts
685
- import { and as and3, eq as eq3, lte } from "drizzle-orm";
703
+ import { and as and4, eq as eq4, lte } from "drizzle-orm";
686
704
  var expirePendingAccountChanges = (db, tenantId, userId) => {
687
705
  const now = (/* @__PURE__ */ new Date()).toISOString();
688
706
  return db.update(accountChangesInIam).set({
689
707
  status: "expired",
690
708
  updatedAt: now
691
709
  }).where(
692
- and3(
693
- eq3(accountChangesInIam.tenantId, tenantId),
694
- eq3(accountChangesInIam.userId, userId),
695
- eq3(accountChangesInIam.status, "pending"),
710
+ and4(
711
+ eq4(accountChangesInIam.tenantId, tenantId),
712
+ eq4(accountChangesInIam.userId, userId),
713
+ eq4(accountChangesInIam.status, "pending"),
696
714
  lte(accountChangesInIam.expiresAt, now)
697
715
  )
698
716
  );
699
717
  };
700
718
 
701
719
  // 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";
720
+ import { and as and5, desc, eq as eq5, gt as gt2 } from "drizzle-orm";
703
721
  var findPendingAccountChange = async (db, tenantId, userId) => {
704
722
  const now = (/* @__PURE__ */ new Date()).toISOString();
705
723
  return await db.select({
@@ -708,10 +726,10 @@ var findPendingAccountChange = async (db, tenantId, userId) => {
708
726
  newPhone: accountChangesInIam.newPhone,
709
727
  expiresAt: accountChangesInIam.expiresAt
710
728
  }).from(accountChangesInIam).where(
711
- and4(
712
- eq4(accountChangesInIam.tenantId, tenantId),
713
- eq4(accountChangesInIam.userId, userId),
714
- eq4(accountChangesInIam.status, "pending"),
729
+ and5(
730
+ eq5(accountChangesInIam.tenantId, tenantId),
731
+ eq5(accountChangesInIam.userId, userId),
732
+ eq5(accountChangesInIam.status, "pending"),
715
733
  gt2(accountChangesInIam.expiresAt, now)
716
734
  )
717
735
  ).orderBy(desc(accountChangesInIam.createdAt)).limit(1).then(([row]) => {
@@ -731,18 +749,18 @@ var findPendingAccountChange = async (db, tenantId, userId) => {
731
749
  };
732
750
 
733
751
  // 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";
752
+ import { and as and6, desc as desc2, eq as eq6, gt as gt3 } from "drizzle-orm";
735
753
  var findActiveVerificationId = async (db, tenantId, userId, type, to) => {
736
754
  const now = (/* @__PURE__ */ new Date()).toISOString();
737
755
  return await db.select({
738
756
  verificationId: verificationsInIam.id,
739
757
  expiresAt: verificationsInIam.expiresAt
740
758
  }).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),
759
+ and6(
760
+ eq6(verificationsInIam.tenantId, tenantId),
761
+ eq6(verificationsInIam.userId, userId),
762
+ eq6(verificationsInIam.type, type),
763
+ eq6(verificationsInIam.to, to),
746
764
  gt3(verificationsInIam.expiresAt, now)
747
765
  )
748
766
  ).orderBy(desc2(verificationsInIam.createdAt)).limit(1).then(([row]) => row ? row : null);
@@ -823,7 +841,7 @@ var accountChangePendingHandler = async (c) => {
823
841
  };
824
842
 
825
843
  // src/db/orm/iam/users/find-user-by-email.ts
826
- import { and as and6, eq as eq6, sql as sql2 } from "drizzle-orm";
844
+ import { and as and7, eq as eq7, sql as sql2 } from "drizzle-orm";
827
845
  var findUserByEmail = (db, tenantId, email) => {
828
846
  return db.select({
829
847
  id: usersInIam.id,
@@ -837,15 +855,15 @@ var findUserByEmail = (db, tenantId, email) => {
837
855
  phoneVerified: usersInIam.phoneVerified,
838
856
  lastSignInAt: usersInIam.lastSignInAt
839
857
  }).from(usersInIam).where(
840
- and6(
841
- eq6(usersInIam.tenantId, tenantId),
858
+ and7(
859
+ eq7(usersInIam.tenantId, tenantId),
842
860
  sql2`lower(${usersInIam.email}) = lower(${email})`
843
861
  )
844
862
  ).limit(1).then(([user]) => user || null);
845
863
  };
846
864
 
847
865
  // src/db/orm/iam/users/find-user-by-phone.ts
848
- import { and as and7, eq as eq7 } from "drizzle-orm";
866
+ import { and as and8, eq as eq8 } from "drizzle-orm";
849
867
  var findUserByPhone = (db, tenantId, phone) => {
850
868
  return db.select({
851
869
  id: usersInIam.id,
@@ -858,7 +876,7 @@ var findUserByPhone = (db, tenantId, phone) => {
858
876
  emailVerified: usersInIam.emailVerified,
859
877
  phoneVerified: usersInIam.phoneVerified,
860
878
  lastSignInAt: usersInIam.lastSignInAt
861
- }).from(usersInIam).where(and7(eq7(usersInIam.tenantId, tenantId), eq7(usersInIam.phone, phone))).limit(1).then(([user]) => user || null);
879
+ }).from(usersInIam).where(and8(eq8(usersInIam.tenantId, tenantId), eq8(usersInIam.phone, phone))).limit(1).then(([user]) => user || null);
862
880
  };
863
881
 
864
882
  // src/db/orm/iam/users/find-user-by-identifier.ts
@@ -913,22 +931,22 @@ var insertSession = (db, data) => {
913
931
  };
914
932
 
915
933
  // src/db/orm/iam/users/update-user-verified.ts
916
- import { and as and8, eq as eq8 } from "drizzle-orm";
934
+ import { and as and9, eq as eq9 } from "drizzle-orm";
917
935
  var updateUserVerified = (db, tenantId, userId, type) => {
918
936
  return db.update(usersInIam).set({
919
937
  [type === "email" ? "emailVerified" : "phoneVerified"]: true,
920
938
  lastSignInAt: (/* @__PURE__ */ new Date()).toISOString()
921
- }).where(and8(eq8(usersInIam.id, userId), eq8(usersInIam.tenantId, tenantId)));
939
+ }).where(and9(eq9(usersInIam.id, userId), eq9(usersInIam.tenantId, tenantId)));
922
940
  };
923
941
 
924
942
  // src/db/orm/iam/verifications/consume-verification.ts
925
- import { eq as eq9 } from "drizzle-orm";
943
+ import { eq as eq10 } from "drizzle-orm";
926
944
  var consumeVerification = (db, verificationId) => {
927
- return db.delete(verificationsInIam).where(eq9(verificationsInIam.id, verificationId));
945
+ return db.delete(verificationsInIam).where(eq10(verificationsInIam.id, verificationId));
928
946
  };
929
947
 
930
948
  // src/db/orm/iam/verifications/find-verification-by-id.ts
931
- import { eq as eq10 } from "drizzle-orm";
949
+ import { eq as eq11 } from "drizzle-orm";
932
950
  var findVerificationById = (db, verificationId) => {
933
951
  return db.select({
934
952
  id: verificationsInIam.id,
@@ -940,17 +958,17 @@ var findVerificationById = (db, verificationId) => {
940
958
  expiresAt: verificationsInIam.expiresAt,
941
959
  createdAt: verificationsInIam.createdAt,
942
960
  attempt: verificationsInIam.attempt
943
- }).from(verificationsInIam).where(eq10(verificationsInIam.id, verificationId)).limit(1).then(([verification]) => verification || null);
961
+ }).from(verificationsInIam).where(eq11(verificationsInIam.id, verificationId)).limit(1).then(([verification]) => verification || null);
944
962
  };
945
963
 
946
964
  // src/db/orm/iam/verifications/update-verification-attempt.ts
947
- import { eq as eq11 } from "drizzle-orm";
965
+ import { eq as eq12 } from "drizzle-orm";
948
966
  var updateVerificationAttempt = async (db, verificationId) => {
949
967
  const verification = await findVerificationById(db, verificationId);
950
968
  if (!verification) {
951
969
  return;
952
970
  }
953
- await db.update(verificationsInIam).set({ attempt: (verification.attempt || 0) + 1 }).where(eq11(verificationsInIam.id, verificationId));
971
+ await db.update(verificationsInIam).set({ attempt: (verification.attempt || 0) + 1 }).where(eq12(verificationsInIam.id, verificationId));
954
972
  };
955
973
 
956
974
  // src/lib/session.ts
@@ -1063,7 +1081,7 @@ var emailVerificationConfirmHandler = async (c) => {
1063
1081
  import { HTTPException as HTTPException4 } from "hono/http-exception";
1064
1082
 
1065
1083
  // src/db/orm/iam/account-changes/cancel-pending-account-changes.ts
1066
- import { and as and9, eq as eq12 } from "drizzle-orm";
1084
+ import { and as and10, eq as eq13 } from "drizzle-orm";
1067
1085
  var cancelPendingAccountChanges = (db, tenantId, userId, changeType) => {
1068
1086
  const now = (/* @__PURE__ */ new Date()).toISOString();
1069
1087
  return db.update(accountChangesInIam).set({
@@ -1072,11 +1090,11 @@ var cancelPendingAccountChanges = (db, tenantId, userId, changeType) => {
1072
1090
  updatedAt: now,
1073
1091
  reason: "replaced"
1074
1092
  }).where(
1075
- and9(
1076
- eq12(accountChangesInIam.tenantId, tenantId),
1077
- eq12(accountChangesInIam.userId, userId),
1078
- eq12(accountChangesInIam.changeType, changeType),
1079
- eq12(accountChangesInIam.status, "pending")
1093
+ and10(
1094
+ eq13(accountChangesInIam.tenantId, tenantId),
1095
+ eq13(accountChangesInIam.userId, userId),
1096
+ eq13(accountChangesInIam.changeType, changeType),
1097
+ eq13(accountChangesInIam.status, "pending")
1080
1098
  )
1081
1099
  );
1082
1100
  };
@@ -1099,13 +1117,13 @@ var insertPendingEmailChange = (db, data) => {
1099
1117
  };
1100
1118
 
1101
1119
  // src/db/orm/iam/verifications/delete-verifications-by-user-and-type.ts
1102
- import { and as and10, eq as eq13 } from "drizzle-orm";
1120
+ import { and as and11, eq as eq14 } from "drizzle-orm";
1103
1121
  var deleteVerificationsByUserAndType = (db, tenantId, userId, type) => {
1104
1122
  return db.delete(verificationsInIam).where(
1105
- and10(
1106
- eq13(verificationsInIam.tenantId, tenantId),
1107
- eq13(verificationsInIam.userId, userId),
1108
- eq13(verificationsInIam.type, type)
1123
+ and11(
1124
+ eq14(verificationsInIam.tenantId, tenantId),
1125
+ eq14(verificationsInIam.userId, userId),
1126
+ eq14(verificationsInIam.type, type)
1109
1127
  )
1110
1128
  );
1111
1129
  };
@@ -1326,7 +1344,7 @@ import { getCookie } from "hono/cookie";
1326
1344
  import { HTTPException as HTTPException6 } from "hono/http-exception";
1327
1345
 
1328
1346
  // src/db/orm/iam/accounts/find-account-by-provider.ts
1329
- import { and as and11, eq as eq14 } from "drizzle-orm";
1347
+ import { and as and12, eq as eq15 } from "drizzle-orm";
1330
1348
  var findAccountByProvider = (db, tenantId, userId, provider) => {
1331
1349
  return db.select({
1332
1350
  id: accountsInIam.id,
@@ -1336,34 +1354,34 @@ var findAccountByProvider = (db, tenantId, userId, provider) => {
1336
1354
  providerAccountId: accountsInIam.providerAccountId,
1337
1355
  password: accountsInIam.password
1338
1356
  }).from(accountsInIam).where(
1339
- and11(
1340
- eq14(accountsInIam.tenantId, tenantId),
1341
- eq14(accountsInIam.userId, userId),
1342
- eq14(accountsInIam.provider, provider)
1357
+ and12(
1358
+ eq15(accountsInIam.tenantId, tenantId),
1359
+ eq15(accountsInIam.userId, userId),
1360
+ eq15(accountsInIam.provider, provider)
1343
1361
  )
1344
1362
  ).limit(1).then(([account]) => account || null);
1345
1363
  };
1346
1364
 
1347
1365
  // src/db/orm/iam/accounts/update-account-password.ts
1348
- import { and as and12, eq as eq15 } from "drizzle-orm";
1366
+ import { and as and13, eq as eq16 } from "drizzle-orm";
1349
1367
  var updateAccountPassword = (db, tenantId, userId, password) => {
1350
1368
  return db.update(accountsInIam).set({ password }).where(
1351
- and12(
1352
- eq15(accountsInIam.tenantId, tenantId),
1353
- eq15(accountsInIam.userId, userId),
1354
- eq15(accountsInIam.provider, "credentials")
1369
+ and13(
1370
+ eq16(accountsInIam.tenantId, tenantId),
1371
+ eq16(accountsInIam.userId, userId),
1372
+ eq16(accountsInIam.provider, "credentials")
1355
1373
  )
1356
1374
  );
1357
1375
  };
1358
1376
 
1359
1377
  // src/db/orm/iam/sessions/delete-session-by-id.ts
1360
- import { eq as eq16 } from "drizzle-orm";
1378
+ import { eq as eq17 } from "drizzle-orm";
1361
1379
  var deleteSessionById = (db, sessionId) => {
1362
- return db.delete(sessionsInIam).where(eq16(sessionsInIam.id, sessionId));
1380
+ return db.delete(sessionsInIam).where(eq17(sessionsInIam.id, sessionId));
1363
1381
  };
1364
1382
 
1365
1383
  // 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";
1384
+ import { and as and14, asc, eq as eq18, gt as gt4 } from "drizzle-orm";
1367
1385
  var listSessionsForUser = (db, tenantId, userId) => {
1368
1386
  return db.select({
1369
1387
  id: sessionsInIam.id,
@@ -1375,9 +1393,9 @@ var listSessionsForUser = (db, tenantId, userId) => {
1375
1393
  userAgent: sessionsInIam.userAgent,
1376
1394
  ip: sessionsInIam.ip
1377
1395
  }).from(sessionsInIam).where(
1378
- and13(
1379
- eq17(sessionsInIam.tenantId, tenantId),
1380
- eq17(sessionsInIam.userId, userId),
1396
+ and14(
1397
+ eq18(sessionsInIam.tenantId, tenantId),
1398
+ eq18(sessionsInIam.userId, userId),
1381
1399
  gt4(sessionsInIam.expiresAt, (/* @__PURE__ */ new Date()).toISOString())
1382
1400
  )
1383
1401
  ).orderBy(asc(sessionsInIam.createdAt)).then((sessions) => sessions);
@@ -1854,9 +1872,9 @@ var deleteOldestSessions = async (db, tenantId, userId, keepCount) => {
1854
1872
  };
1855
1873
 
1856
1874
  // src/db/orm/iam/users/update-last-sign-in.ts
1857
- import { and as and14, eq as eq18 } from "drizzle-orm";
1875
+ import { and as and15, eq as eq19 } from "drizzle-orm";
1858
1876
  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)));
1877
+ return db.update(usersInIam).set({ lastSignInAt: (/* @__PURE__ */ new Date()).toISOString(), loginAttempt: 0 }).where(and15(eq19(usersInIam.id, userId), eq19(usersInIam.tenantId, tenantId)));
1860
1878
  };
1861
1879
 
1862
1880
  // src/routes/handler/sign-in.ts
@@ -2009,7 +2027,7 @@ var insertCredentialsAccount = (db, data) => {
2009
2027
  };
2010
2028
 
2011
2029
  // src/db/orm/iam/users/find-user-by-handle.ts
2012
- import { and as and15, eq as eq19, sql as sql3 } from "drizzle-orm";
2030
+ import { and as and16, eq as eq20, sql as sql3 } from "drizzle-orm";
2013
2031
  var findUserByHandle = (db, tenantId, handle) => {
2014
2032
  return db.select({
2015
2033
  id: usersInIam.id,
@@ -2023,8 +2041,8 @@ var findUserByHandle = (db, tenantId, handle) => {
2023
2041
  phoneVerified: usersInIam.phoneVerified,
2024
2042
  lastSignInAt: usersInIam.lastSignInAt
2025
2043
  }).from(usersInIam).where(
2026
- and15(
2027
- eq19(usersInIam.tenantId, tenantId),
2044
+ and16(
2045
+ eq20(usersInIam.tenantId, tenantId),
2028
2046
  sql3`lower(${usersInIam.handle}) = lower(${handle})`
2029
2047
  )
2030
2048
  ).limit(1).then(([user]) => user || null);
@@ -2179,58 +2197,58 @@ var signUpHandler = async (c) => {
2179
2197
  import { HTTPException as HTTPException13 } from "hono/http-exception";
2180
2198
 
2181
2199
  // src/db/orm/iam/account-changes/mark-pending-account-change-applied.ts
2182
- import { and as and16, eq as eq20 } from "drizzle-orm";
2200
+ import { and as and17, eq as eq21 } from "drizzle-orm";
2183
2201
  var markPendingAccountChangeApplied = (db, tenantId, userId, changeType, newValue) => {
2184
2202
  const now = (/* @__PURE__ */ new Date()).toISOString();
2185
- const valueCondition = changeType === "email" ? eq20(accountChangesInIam.newEmail, newValue) : eq20(accountChangesInIam.newPhone, newValue);
2203
+ const valueCondition = changeType === "email" ? eq21(accountChangesInIam.newEmail, newValue) : eq21(accountChangesInIam.newPhone, newValue);
2186
2204
  return db.update(accountChangesInIam).set({
2187
2205
  status: "applied",
2188
2206
  confirmedAt: now,
2189
2207
  updatedAt: now
2190
2208
  }).where(
2191
- and16(
2192
- eq20(accountChangesInIam.tenantId, tenantId),
2193
- eq20(accountChangesInIam.userId, userId),
2194
- eq20(accountChangesInIam.changeType, changeType),
2195
- eq20(accountChangesInIam.status, "pending"),
2209
+ and17(
2210
+ eq21(accountChangesInIam.tenantId, tenantId),
2211
+ eq21(accountChangesInIam.userId, userId),
2212
+ eq21(accountChangesInIam.changeType, changeType),
2213
+ eq21(accountChangesInIam.status, "pending"),
2196
2214
  valueCondition
2197
2215
  )
2198
2216
  );
2199
2217
  };
2200
2218
 
2201
2219
  // src/db/orm/iam/accounts/update-credentials-provider-account-id.ts
2202
- import { and as and17, eq as eq21 } from "drizzle-orm";
2220
+ import { and as and18, eq as eq22 } from "drizzle-orm";
2203
2221
  var updateCredentialsProviderAccountId = async (db, tenantId, userId, providerAccountId) => {
2204
2222
  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")
2223
+ and18(
2224
+ eq22(accountsInIam.tenantId, tenantId),
2225
+ eq22(accountsInIam.userId, userId),
2226
+ eq22(accountsInIam.provider, "credentials")
2209
2227
  )
2210
2228
  ).returning({ id: accountsInIam.id }).then(([row]) => row?.id);
2211
2229
  return Boolean(updated);
2212
2230
  };
2213
2231
 
2214
2232
  // src/db/orm/iam/sessions/delete-other-sessions.ts
2215
- import { and as and18, eq as eq22, ne } from "drizzle-orm";
2233
+ import { and as and19, eq as eq23, ne } from "drizzle-orm";
2216
2234
  var deleteOtherSessions = (db, tenantId, userId, currentSessionId) => {
2217
2235
  return db.delete(sessionsInIam).where(
2218
- and18(
2219
- eq22(sessionsInIam.tenantId, tenantId),
2220
- eq22(sessionsInIam.userId, userId),
2236
+ and19(
2237
+ eq23(sessionsInIam.tenantId, tenantId),
2238
+ eq23(sessionsInIam.userId, userId),
2221
2239
  ne(sessionsInIam.id, currentSessionId)
2222
2240
  )
2223
2241
  );
2224
2242
  };
2225
2243
 
2226
2244
  // src/db/orm/iam/users/update-user-email.ts
2227
- import { and as and19, eq as eq23, sql as sql4 } from "drizzle-orm";
2245
+ import { and as and20, eq as eq24, sql as sql4 } from "drizzle-orm";
2228
2246
  var updateUserEmail = (db, tenantId, userId, email) => {
2229
2247
  return db.update(usersInIam).set({
2230
2248
  email,
2231
2249
  emailVerified: true,
2232
2250
  updatedAt: sql4`CURRENT_TIMESTAMP`
2233
- }).where(and19(eq23(usersInIam.id, userId), eq23(usersInIam.tenantId, tenantId))).returning({
2251
+ }).where(and20(eq24(usersInIam.id, userId), eq24(usersInIam.tenantId, tenantId))).returning({
2234
2252
  id: usersInIam.id,
2235
2253
  tenantId: usersInIam.tenantId,
2236
2254
  fullName: usersInIam.fullName,
@@ -2287,13 +2305,13 @@ var updateEmailHandler = async (c) => {
2287
2305
  import { HTTPException as HTTPException14 } from "hono/http-exception";
2288
2306
 
2289
2307
  // src/db/orm/iam/users/update-user-phone.ts
2290
- import { and as and20, eq as eq24, sql as sql5 } from "drizzle-orm";
2308
+ import { and as and21, eq as eq25, sql as sql5 } from "drizzle-orm";
2291
2309
  var updateUserPhone = (db, tenantId, userId, phone) => {
2292
2310
  return db.update(usersInIam).set({
2293
2311
  phone,
2294
2312
  phoneVerified: true,
2295
2313
  updatedAt: sql5`CURRENT_TIMESTAMP`
2296
- }).where(and20(eq24(usersInIam.id, userId), eq24(usersInIam.tenantId, tenantId))).returning({
2314
+ }).where(and21(eq25(usersInIam.id, userId), eq25(usersInIam.tenantId, tenantId))).returning({
2297
2315
  id: usersInIam.id,
2298
2316
  tenantId: usersInIam.tenantId,
2299
2317
  fullName: usersInIam.fullName,
@@ -2350,7 +2368,7 @@ var updatePhoneHandler = async (c) => {
2350
2368
  import { HTTPException as HTTPException15 } from "hono/http-exception";
2351
2369
 
2352
2370
  // src/db/orm/iam/users/update-user-profile.ts
2353
- import { and as and21, eq as eq25, sql as sql6 } from "drizzle-orm";
2371
+ import { and as and22, eq as eq26, sql as sql6 } from "drizzle-orm";
2354
2372
  var updateUserProfile = async (db, tenantId, userId, data) => {
2355
2373
  const updateData = {};
2356
2374
  if (data.fullName !== void 0) {
@@ -2359,7 +2377,7 @@ var updateUserProfile = async (db, tenantId, userId, data) => {
2359
2377
  return await db.update(usersInIam).set({
2360
2378
  ...updateData,
2361
2379
  updatedAt: sql6`CURRENT_TIMESTAMP`
2362
- }).where(and21(eq25(usersInIam.id, userId), eq25(usersInIam.tenantId, tenantId))).returning({
2380
+ }).where(and22(eq26(usersInIam.id, userId), eq26(usersInIam.tenantId, tenantId))).returning({
2363
2381
  id: usersInIam.id,
2364
2382
  tenantId: usersInIam.tenantId,
2365
2383
  fullName: usersInIam.fullName,
@@ -2926,9 +2944,14 @@ var createAuthMiddleware = (config, database, getTenantId) => {
2926
2944
  session.userId
2927
2945
  );
2928
2946
  if (user) {
2947
+ const userRoles = await findUserRoles(
2948
+ database,
2949
+ session.tenantId,
2950
+ session.userId
2951
+ );
2929
2952
  c.set("tenantId", enableTenant ? session.tenantId : tenantId);
2930
2953
  c.set("userId", user.id);
2931
- c.set("user", user);
2954
+ c.set("user", { ...user, userRoles: userRoles || [] });
2932
2955
  c.set("session", session);
2933
2956
  }
2934
2957
  }