@getstrata/starter 2.2.30 → 2.2.32

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
@@ -1242,6 +1242,9 @@ function renderAuthModule(layers) {
1242
1242
  imports.push(`import { appUrl } from "@getstrata/core/runtime/appKeyPrefix";`);
1243
1243
  }
1244
1244
  }
1245
+ if (mfa) {
1246
+ imports.push(`import { ConflictError } from "@getstrata/core/errors/http";`);
1247
+ }
1245
1248
  if (jsonApi) {
1246
1249
  imports.push(`import { AuthManager } from "@getstrata/core/auth/guard";`);
1247
1250
  }
@@ -1370,6 +1373,21 @@ async function revokeUserSessions(userId: number) {
1370
1373
  });
1371
1374
  }
1372
1375
 
1376
+ ${verify ? `
1377
+ async function completeSignedEmailVerification(request: Request): Promise<boolean> {
1378
+ return await runInTransaction(async () => {
1379
+ const userId = await consumeSignedAuthToken(request, AUTH_ONE_TIME_PURPOSES.emailVerify);
1380
+ if (!userId) return false;
1381
+ await runAuthWrite(userId, async () => {
1382
+ const user = await User.find(userId);
1383
+ if (!user) throw new Error("Verification account no longer exists.");
1384
+ await user.update({ email_verified_at: ${nowTimestampLiteral(layers.database)} });
1385
+ });
1386
+ return true;
1387
+ });
1388
+ }
1389
+ ` : ""}
1390
+
1373
1391
  async function completeSignedPasswordReset(request: Request, password: unknown): Promise<boolean> {
1374
1392
  if (typeof password !== "string" || password.length < 8) return false;
1375
1393
  return await runInTransaction(async () => {
@@ -1589,14 +1607,9 @@ async function completeBrowserSsoLogin(
1589
1607
  const jsonVerify = jsonApi && verify ? `
1590
1608
  "/api/v1/auth/verify-email": {
1591
1609
  POST: kernel.wrap("api", kernel.wrapSigned(withErrorHandling(async (request) => {
1592
- const id = await consumeSignedAuthToken(request, AUTH_ONE_TIME_PURPOSES.emailVerify);
1593
- if (!id) {
1610
+ if (!(await completeSignedEmailVerification(request))) {
1594
1611
  return jsonResponse({ error: "Invalid or expired verification link." }, { status: 403 });
1595
1612
  }
1596
- await runAuthWrite(id, async () => {
1597
- const user = await User.find(id);
1598
- await user?.update({ email_verified_at: ${nowTimestampLiteral(layers.database)} });
1599
- });
1600
1613
  return jsonResponse({ ok: true });
1601
1614
  }))),
1602
1615
  },` : "";
@@ -1908,12 +1921,7 @@ async function completeBrowserSsoLogin(
1908
1921
  const url = new URL(request.url);
1909
1922
  if (url.searchParams.get("signature")) {
1910
1923
  assertValidSignature(request);
1911
- const id = await consumeSignedAuthToken(request, AUTH_ONE_TIME_PURPOSES.emailVerify);
1912
- if (id) {
1913
- await runAuthWrite(id, async () => {
1914
- const user = await User.find(id);
1915
- await user?.update({ email_verified_at: ${nowTimestampLiteral(layers.database)} });
1916
- });
1924
+ if (await completeSignedEmailVerification(request)) {
1917
1925
  return flashResponse(
1918
1926
  redirectTo("/login"),
1919
1927
  { level: "success", message: "Email verified. Sign in." },
@@ -2019,15 +2027,26 @@ async function completeBrowserSsoLogin(
2019
2027
  }
2020
2028
  const recoveryCodes = generateRecoveryCodes();
2021
2029
  const stored = protectMfaSecret(secret);
2022
- await runAuthWrite(Number(user.id), async () => {
2023
- const record = await User.find(Number(user.id));
2024
- await record?.update({
2025
- mfa_secret: stored,
2026
- mfa_enabled: true,
2027
- mfa_recovery_codes: JSON.stringify(recoveryCodes.map((item) => hashRecoveryCode(item))),
2030
+ const previous = await runAuthWrite(Number(user.id), () => User.find(Number(user.id)));
2031
+ if (!previous) throw new ConflictError("MFA configuration changed. Reload and confirm again.");
2032
+ await runInTransaction(async () => {
2033
+ await runAuthWrite(Number(user.id), async () => {
2034
+ // Trusted, pre-protected security fields: atomically replace only the state we read.
2035
+ const changed = await previous.getRepository().updateWhere({
2036
+ mfa_secret: stored,
2037
+ mfa_enabled: true,
2038
+ mfa_recovery_codes: JSON.stringify(recoveryCodes.map((item) => hashRecoveryCode(item))),
2039
+ }, { where: {
2040
+ id: Number(user.id),
2041
+ mfa_enabled: previous.get("mfa_enabled"),
2042
+ mfa_secret: previous.get("mfa_secret"),
2043
+ mfa_recovery_codes: previous.get("mfa_recovery_codes"),
2044
+ session_valid_after: previous.get("session_valid_after"),
2045
+ } });
2046
+ if (changed !== 1) throw new ConflictError("MFA configuration changed. Reload and confirm again.");
2028
2047
  });
2048
+ await revokeUserSessions(Number(user.id));
2029
2049
  });
2030
- await revokeUserSessions(Number(user.id));
2031
2050
  return views.render("mfa-setup.eta", {
2032
2051
  layout: { title: "MFA" },
2033
2052
  errors: {},
@@ -3144,9 +3163,9 @@ function renderPackageJson(projectName, options = {}) {
3144
3163
  "@getstrata/cli": "workspace:*",
3145
3164
  "@getstrata/core": "workspace:*"
3146
3165
  } : {
3147
- "@getstrata/bootstrap": "^2.2.30",
3148
- "@getstrata/cli": "^2.2.30",
3149
- "@getstrata/core": "^2.2.30"
3166
+ "@getstrata/bootstrap": "^2.2.32",
3167
+ "@getstrata/cli": "^2.2.32",
3168
+ "@getstrata/core": "^2.2.32"
3150
3169
  };
3151
3170
  coreDeps.eta = "^4.6.0";
3152
3171
  if (options.layers?.database === "mysql") {
@@ -12,9 +12,9 @@
12
12
  "check": "tsc --noEmit"
13
13
  },
14
14
  "dependencies": {
15
- "@getstrata/bootstrap": "^2.2.30",
16
- "@getstrata/cli": "^2.2.30",
17
- "@getstrata/core": "^2.2.30",
15
+ "@getstrata/bootstrap": "^2.2.32",
16
+ "@getstrata/cli": "^2.2.32",
17
+ "@getstrata/core": "^2.2.32",
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.30",
3
+ "version": "2.2.32",
4
4
  "description": "Interactive create-strata wizard. Choose each layer; one database engine.",
5
5
  "type": "module",
6
6
  "license": "MIT",