@getstrata/starter 2.2.27 → 2.2.29

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/cli.js CHANGED
@@ -1248,6 +1248,7 @@ function renderAuthModule(layers) {
1248
1248
  if (authUsesJwt(layers.auth)) {
1249
1249
  imports.push(`import { jwtTtlSeconds, signJwt } from "@getstrata/core/auth/jwt";`);
1250
1250
  }
1251
+ imports.push(`import { runInTransaction } from "@getstrata/core/database/transaction";`);
1251
1252
  imports.push(`import { hashPassword, verifyPassword } from "@getstrata/core/auth/password";`);
1252
1253
  imports.push(`import { AUTH_ONE_TIME_PURPOSES, consumeOneTimeToken, generateOneTimeToken, hashOneTimeToken, revokeUserSessions as revokeStoredUserSessions } from "@getstrata/core/auth/oneTimeToken";`);
1253
1254
  imports.push(`import { completePasswordLogin, persistConsumedRecoveryHash } from "@getstrata/core/auth/passwordLogin";`);
@@ -1369,6 +1370,21 @@ async function revokeUserSessions(userId: number) {
1369
1370
  });
1370
1371
  }
1371
1372
 
1373
+ async function completeSignedPasswordReset(request: Request, password: unknown): Promise<boolean> {
1374
+ if (typeof password !== "string" || password.length < 8) return false;
1375
+ return await runInTransaction(async () => {
1376
+ const userId = await consumeSignedAuthToken(request, AUTH_ONE_TIME_PURPOSES.passwordReset);
1377
+ if (!userId) return false;
1378
+ await runAuthWrite(userId, async () => {
1379
+ const user = await User.find(userId);
1380
+ if (!user) throw new Error("Reset account no longer exists.");
1381
+ await user.update({ password: await hashPassword(password) });
1382
+ await revokeStoredUserSessions(getSql(), userId);
1383
+ });
1384
+ return true;
1385
+ });
1386
+ }
1387
+
1372
1388
  async function persistAuthRecovery(
1373
1389
  userId: number,
1374
1390
  currentRaw: string | null | undefined,
@@ -1562,17 +1578,11 @@ async function completeBrowserSsoLogin(
1562
1578
  },
1563
1579
  "/api/v1/auth/reset-password": {
1564
1580
  POST: kernel.wrap("api", kernel.wrapSigned(withErrorHandling(async (request) => {
1565
- const userId = await consumeSignedAuthToken(request, AUTH_ONE_TIME_PURPOSES.passwordReset);
1566
- const body = (await request.json()) as { password?: string };
1567
- const nextPassword = body.password ?? "";
1568
- if (!userId || nextPassword.length < 8) {
1581
+ const body: unknown = await request.json();
1582
+ const password = typeof body === "object" && body !== null && "password" in body ? body.password : undefined;
1583
+ if (!(await completeSignedPasswordReset(request, password))) {
1569
1584
  return jsonResponse({ error: "Invalid or expired reset link." }, { status: 403 });
1570
1585
  }
1571
- await runAuthWrite(userId, async () => {
1572
- const user = await User.find(userId);
1573
- await user?.update({ password: await hashPassword(nextPassword) });
1574
- });
1575
- await revokeUserSessions(userId);
1576
1586
  return jsonResponse({ ok: true });
1577
1587
  }))),
1578
1588
  },` : "";
@@ -1881,18 +1891,12 @@ async function completeBrowserSsoLogin(
1881
1891
  return views.render("reset-password.eta", { layout: { title: "Reset password" }, errors: {}, password: "", email, action: \`\${new URL(request.url).pathname}\${new URL(request.url).search}\` }, { request });
1882
1892
  })),
1883
1893
  POST: kernel.wrapWeb(kernel.wrapSigned(async (request) => {
1884
- const userId = await consumeSignedAuthToken(request, AUTH_ONE_TIME_PURPOSES.passwordReset);
1885
1894
  const { fields } = await parseFormBody(request);
1886
1895
  const email = new URL(request.url).searchParams.get("email") ?? fields.email ?? "";
1887
1896
  const password = fields.password ?? "";
1888
- if (!userId || !email || password.length < 8) {
1897
+ if (!email || !(await completeSignedPasswordReset(request, password))) {
1889
1898
  return views.render("reset-password.eta", { layout: { title: "Reset password" }, errors: { password: "Invalid or expired reset link." }, password: "", email, action: \`\${new URL(request.url).pathname}\${new URL(request.url).search}\` }, { request });
1890
1899
  }
1891
- await runAuthWrite(userId, async () => {
1892
- const user = await User.find(userId);
1893
- await user?.update({ password: await hashPassword(password) });
1894
- });
1895
- await revokeUserSessions(userId);
1896
1900
  return flashResponse(redirectTo("/login"), { level: "success", message: "Password updated. Sign in." });
1897
1901
  })),
1898
1902
  },
@@ -3140,9 +3144,9 @@ function renderPackageJson(projectName, options = {}) {
3140
3144
  "@getstrata/cli": "workspace:*",
3141
3145
  "@getstrata/core": "workspace:*"
3142
3146
  } : {
3143
- "@getstrata/bootstrap": "^2.2.27",
3144
- "@getstrata/cli": "^2.2.27",
3145
- "@getstrata/core": "^2.2.27"
3147
+ "@getstrata/bootstrap": "^2.2.29",
3148
+ "@getstrata/cli": "^2.2.29",
3149
+ "@getstrata/core": "^2.2.29"
3146
3150
  };
3147
3151
  coreDeps.eta = "^4.6.0";
3148
3152
  if (options.layers?.database === "mysql") {
@@ -12,9 +12,9 @@
12
12
  "check": "tsc --noEmit"
13
13
  },
14
14
  "dependencies": {
15
- "@getstrata/bootstrap": "^2.2.27",
16
- "@getstrata/cli": "^2.2.27",
17
- "@getstrata/core": "^2.2.27",
15
+ "@getstrata/bootstrap": "^2.2.29",
16
+ "@getstrata/cli": "^2.2.29",
17
+ "@getstrata/core": "^2.2.29",
18
18
  "eta": "^4.6.0"
19
19
  },
20
20
  "devDependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/starter",
3
- "version": "2.2.27",
3
+ "version": "2.2.29",
4
4
  "description": "Interactive create-strata wizard. Choose each layer; one database engine.",
5
5
  "type": "module",
6
6
  "license": "MIT",