@fonderie/auth 7.1.0 → 7.1.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.cjs CHANGED
@@ -1149,7 +1149,7 @@ function mfaController(store, config, issuer, bus) {
1149
1149
  }
1150
1150
 
1151
1151
  // src/controllers/auth.controller.ts
1152
- var import_node_crypto4 = require("crypto");
1152
+ var import_node_crypto5 = require("crypto");
1153
1153
  var import_events2 = require("@fonderie/events");
1154
1154
  var import_core5 = require("@fonderie/core");
1155
1155
 
@@ -1196,6 +1196,8 @@ function normalizeEmailSafe(email2) {
1196
1196
  }
1197
1197
 
1198
1198
  // src/models/password-reset.model.ts
1199
+ var import_node_crypto4 = require("crypto");
1200
+ var hashSecret = (value) => (0, import_node_crypto4.createHash)("sha256").update(value).digest("hex");
1199
1201
  var PasswordResetModel = class {
1200
1202
  constructor(store) {
1201
1203
  this.store = store;
@@ -1207,7 +1209,7 @@ var PasswordResetModel = class {
1207
1209
  VALUES ($1, $2, $3, $4, now())
1208
1210
  ON CONFLICT (user_id) DO UPDATE
1209
1211
  SET pin = $2, token = $3, expires_at = $4, created_at = now()`,
1210
- [userId, pin, token, expiresAt]
1212
+ [userId, hashSecret(pin), hashSecret(token), expiresAt]
1211
1213
  );
1212
1214
  }
1213
1215
  async findLastSentAt(userId) {
@@ -1221,7 +1223,7 @@ var PasswordResetModel = class {
1221
1223
  async findByPin(pin) {
1222
1224
  const [row] = await this.store.query(
1223
1225
  `SELECT user_id, expires_at FROM fonderie_password_resets WHERE pin = $1`,
1224
- [pin]
1226
+ [hashSecret(pin)]
1225
1227
  );
1226
1228
  if (!row) return null;
1227
1229
  return { userId: row.user_id, expiresAt: new Date(row.expires_at) };
@@ -1234,7 +1236,7 @@ var PasswordResetModel = class {
1234
1236
  if (typeof token !== "string" || token.length < 32) return null;
1235
1237
  const [row] = await this.store.query(
1236
1238
  `SELECT user_id, expires_at FROM fonderie_password_resets WHERE token = $1`,
1237
- [token]
1239
+ [hashSecret(token)]
1238
1240
  );
1239
1241
  if (!row) return null;
1240
1242
  return { userId: row.user_id, expiresAt: new Date(row.expires_at) };
@@ -1387,7 +1389,7 @@ function authController(store, config, bus) {
1387
1389
  if (!row) {
1388
1390
  return (0, import_core5.setApiResponse)(import_core5.HTTP.SERVER_ERROR, "SERVER_ERROR", "Registration failed");
1389
1391
  }
1390
- const pin = (0, import_node_crypto4.randomInt)(1e5, 1e6).toString();
1392
+ const pin = (0, import_node_crypto5.randomInt)(1e5, 1e6).toString();
1391
1393
  const expiresAt = new Date(Date.now() + 1e3 * 60 * 60 * 24);
1392
1394
  await emailVerif.create(row.id, pin, expiresAt);
1393
1395
  const user = await users.findById(row.id);
@@ -1451,7 +1453,7 @@ function authController(store, config, bus) {
1451
1453
  firstName ?? null,
1452
1454
  lastName ?? null
1453
1455
  );
1454
- const otp = (0, import_node_crypto4.randomInt)(1e5, 1e6).toString();
1456
+ const otp = (0, import_node_crypto5.randomInt)(1e5, 1e6).toString();
1455
1457
  const expiresAt = new Date(Date.now() + OTP_TTL_MS);
1456
1458
  await phoneVerif.upsert(id, normalizePhone(phone2), otp, expiresAt);
1457
1459
  const user = await users.findById(id);
@@ -1597,7 +1599,7 @@ function authController(store, config, bus) {
1597
1599
  "Account suspended. Please contact support."
1598
1600
  );
1599
1601
  }
1600
- const otp = (0, import_node_crypto4.randomInt)(1e5, 1e6).toString();
1602
+ const otp = (0, import_node_crypto5.randomInt)(1e5, 1e6).toString();
1601
1603
  const expiresAt = new Date(Date.now() + OTP_TTL_MS);
1602
1604
  await phoneVerif.upsert(user.id, normalizePhone(phone2), otp, expiresAt);
1603
1605
  bus?.emit(import_events2.NOTIFICATION_EVENT, {
@@ -1707,8 +1709,8 @@ function authController(store, config, bus) {
1707
1709
  "Password reset email sent (if account exists)."
1708
1710
  );
1709
1711
  }
1710
- const pin = (0, import_node_crypto4.randomInt)(1e5, 1e6).toString();
1711
- const token = (0, import_node_crypto4.randomBytes)(32).toString("hex");
1712
+ const pin = (0, import_node_crypto5.randomInt)(1e5, 1e6).toString();
1713
+ const token = (0, import_node_crypto5.randomBytes)(32).toString("hex");
1712
1714
  const expiresAt = new Date(Date.now() + 1e3 * 60 * 60);
1713
1715
  await passwordReset.create(user.id, pin, token, expiresAt);
1714
1716
  const base = resolved.passwordResetUrl;
@@ -1891,7 +1893,7 @@ function authController(store, config, bus) {
1891
1893
  }
1892
1894
  );
1893
1895
  }
1894
- const otp = (0, import_node_crypto4.randomInt)(1e5, 1e6).toString();
1896
+ const otp = (0, import_node_crypto5.randomInt)(1e5, 1e6).toString();
1895
1897
  const expiresAt2 = new Date(Date.now() + OTP_TTL_MS);
1896
1898
  await phoneVerif.upsert(ctx.user.id, phone2, otp, expiresAt2);
1897
1899
  bus?.emit(import_events2.NOTIFICATION_EVENT, {
@@ -1931,7 +1933,7 @@ function authController(store, config, bus) {
1931
1933
  }
1932
1934
  );
1933
1935
  }
1934
- const pin = (0, import_node_crypto4.randomInt)(1e5, 1e6).toString();
1936
+ const pin = (0, import_node_crypto5.randomInt)(1e5, 1e6).toString();
1935
1937
  const expiresAt = new Date(Date.now() + 1e3 * 60 * 60 * 24);
1936
1938
  await emailVerif.replace(ctx.user.id, pin, expiresAt);
1937
1939
  bus?.emit(import_events2.NOTIFICATION_EVENT, {
@@ -1949,7 +1951,7 @@ function authController(store, config, bus) {
1949
1951
  }
1950
1952
 
1951
1953
  // src/controllers/user.controller.ts
1952
- var import_node_crypto5 = require("crypto");
1954
+ var import_node_crypto6 = require("crypto");
1953
1955
  var import_core7 = require("@fonderie/core");
1954
1956
  var import_events3 = require("@fonderie/events");
1955
1957
 
@@ -2139,7 +2141,7 @@ function userController(store, config, bus) {
2139
2141
  if (existing) {
2140
2142
  return (0, import_core7.setApiResponse)(import_core7.HTTP.CONFLICT, "EMAIL_IN_USE", "Email already in use");
2141
2143
  }
2142
- const pin = (0, import_node_crypto5.randomInt)(1e5, 1e6).toString();
2144
+ const pin = (0, import_node_crypto6.randomInt)(1e5, 1e6).toString();
2143
2145
  const expiresAt = new Date(Date.now() + 1e3 * 60 * 60 * 24);
2144
2146
  await emailVerif.replace(ctx.user.id, pin, expiresAt);
2145
2147
  await users.updateEmail(ctx.user.id, normalised);
@@ -2183,7 +2185,7 @@ function userController(store, config, bus) {
2183
2185
  if (existing) {
2184
2186
  return (0, import_core7.setApiResponse)(import_core7.HTTP.CONFLICT, "PHONE_IN_USE", "Phone number already in use");
2185
2187
  }
2186
- const otp = (0, import_node_crypto5.randomInt)(1e5, 1e6).toString();
2188
+ const otp = (0, import_node_crypto6.randomInt)(1e5, 1e6).toString();
2187
2189
  const expiresAt = new Date(Date.now() + 10 * 60 * 1e3);
2188
2190
  await phoneVerif.upsert(ctx.user.id, normalised, otp, expiresAt);
2189
2191
  await users.updatePhone(ctx.user.id, normalised);
@@ -2292,7 +2294,7 @@ function userController(store, config, bus) {
2292
2294
  }
2293
2295
 
2294
2296
  // src/controllers/oauth.controller.ts
2295
- var import_node_crypto6 = require("crypto");
2297
+ var import_node_crypto7 = require("crypto");
2296
2298
  var import_core8 = require("@fonderie/core");
2297
2299
  function oauthController(store, config) {
2298
2300
  const users = new UserModel(store);
@@ -2308,7 +2310,7 @@ function oauthController(store, config) {
2308
2310
  "Google OAuth not configured"
2309
2311
  );
2310
2312
  }
2311
- const state = (0, import_node_crypto6.randomBytes)(16).toString("hex");
2313
+ const state = (0, import_node_crypto7.randomBytes)(16).toString("hex");
2312
2314
  const params = new URLSearchParams({
2313
2315
  client_id: google.clientId,
2314
2316
  redirect_uri: google.redirectUri,