@mesob/auth-hono 0.4.0 → 0.4.1

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 CHANGED
@@ -1056,17 +1056,17 @@ var checkAccountHandler = async (c) => {
1056
1056
  email: usersInIam.email,
1057
1057
  phone: usersInIam.phone,
1058
1058
  verified: isEmail ? usersInIam.emailVerified : usersInIam.phoneVerified,
1059
- hasPassword: sql4`exists(
1060
- select 1
1061
- from ${accountsInIam}
1062
- where ${accountsInIam.tenantId} = ${resolvedTenantId}
1063
- and ${accountsInIam.userId} = ${usersInIam.id}
1064
- and ${accountsInIam.provider} = 'credentials'
1065
- and ${accountsInIam.password} is not null
1066
- )`
1067
- }).from(usersInIam).where(whereClause).limit(1);
1059
+ password: accountsInIam.password
1060
+ }).from(usersInIam).leftJoin(
1061
+ accountsInIam,
1062
+ and5(
1063
+ eq5(accountsInIam.tenantId, resolvedTenantId),
1064
+ eq5(accountsInIam.userId, usersInIam.id),
1065
+ eq5(accountsInIam.provider, "credentials")
1066
+ )
1067
+ ).where(whereClause).limit(1);
1068
1068
  const verified = result?.verified ?? false;
1069
- const hasPassword = result?.hasPassword ?? false;
1069
+ const hasPassword = Boolean(result?.password);
1070
1070
  return c.json(
1071
1071
  {
1072
1072
  exists: !!result,
@@ -1416,15 +1416,15 @@ var fetchUserForLogin = async ({
1416
1416
  lastSignInAt: usersInIam.lastSignInAt,
1417
1417
  bannedUntil: usersInIam.bannedUntil,
1418
1418
  loginAttempt: usersInIam.loginAttempt,
1419
- hasPassword: sql6`exists(
1420
- select 1
1421
- from ${accountsInIam}
1422
- where ${accountsInIam.tenantId} = ${tenantId}
1423
- and ${accountsInIam.userId} = ${usersInIam.id}
1424
- and ${accountsInIam.provider} = 'credentials'
1425
- and ${accountsInIam.password} is not null
1426
- )`
1427
- }).from(usersInIam).where(whereClause).limit(1);
1419
+ hasPassword: sql6`coalesce(${accountsInIam.password} is not null, false)`
1420
+ }).from(usersInIam).leftJoin(
1421
+ accountsInIam,
1422
+ and7(
1423
+ eq7(accountsInIam.tenantId, tenantId),
1424
+ eq7(accountsInIam.userId, usersInIam.id),
1425
+ eq7(accountsInIam.provider, "credentials")
1426
+ )
1427
+ ).where(whereClause).limit(1);
1428
1428
  return row || null;
1429
1429
  };
1430
1430
  var fetchUserByIdWithRoles = async ({
@@ -1706,7 +1706,7 @@ var signInHandler = (
1706
1706
  eq9(accountsInIam.provider, "credentials")
1707
1707
  )
1708
1708
  ).limit(1);
1709
- if (!(user.hasPassword && account?.password)) {
1709
+ if (!account?.password) {
1710
1710
  logger2.log("[sign-in] 401: no credentials account", { userId: user.id });
1711
1711
  return c.json({ error: AUTH_ERRORS.HAS_NO_PASSWORD }, 401);
1712
1712
  }