create-guren-app 1.21.1 → 1.21.3

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
@@ -1416,7 +1416,8 @@ const blueprintRegistry = {
1416
1416
  resourceExample: {
1417
1417
  name: "tags",
1418
1418
  fields: "name:string"
1419
- }
1419
+ },
1420
+ initialMigration: "create_users_and_posts"
1420
1421
  },
1421
1422
  worker: {
1422
1423
  name: "worker",
@@ -1991,6 +1992,19 @@ async function runCodegen(cwd) {
1991
1992
  consola.success("Generated route and page types");
1992
1993
  return true;
1993
1994
  }
1995
+ /**
1996
+ * `make:migration` exits 0 for "nothing to migrate" as well, so the folder
1997
+ * drizzle-kit writes per migration is the evidence that one exists.
1998
+ */
1999
+ async function generateInitialMigration(cwd, name) {
2000
+ consola.start("Generating the first migration...");
2001
+ if (!(await runAppCli(cwd, ["make:migration", name]) ? await readdir(join(cwd, "db/migrations"), { withFileTypes: true }).catch(() => []) : []).some((entry) => entry.isDirectory())) {
2002
+ consola.warn("The first migration was not generated (see the output above). Run `bun run db:make` inside the app.");
2003
+ return false;
2004
+ }
2005
+ consola.success("Generated the first migration in db/migrations/");
2006
+ return true;
2007
+ }
1994
2008
  runMain(defineCommand({
1995
2009
  meta: {
1996
2010
  name: "create-guren-app",
@@ -2111,6 +2125,7 @@ runMain(defineCommand({
2111
2125
  }
2112
2126
  if (!authInstalled) consola.warn(installed ? "Authentication scaffolding failed (see the output above). Run `bunx guren add auth` inside the app once that is fixed." : "Authentication was not scaffolded automatically. Run `bunx guren add auth` inside the app after installing dependencies.");
2113
2127
  }
2128
+ const migrationGenerated = installed && blueprint.initialMigration !== void 0 && await generateInitialMigration(targetDir, blueprint.initialMigration);
2114
2129
  const authFailed = includeAuth && !authInstalled;
2115
2130
  if (installed && authFailed) consola.info("Skipping codegen until authentication is scaffolded; run `bun run codegen` after `bunx guren add auth`.");
2116
2131
  const codegenRan = installed && !authFailed && await runCodegen(targetDir);
@@ -2132,7 +2147,7 @@ runMain(defineCommand({
2132
2147
  consola.log("");
2133
2148
  consola.info(codegenRan ? "Set up the database:" : "Generate types and set up database:");
2134
2149
  if (!codegenRan) consola.log(" bun run codegen");
2135
- consola.log(" bun run db:make");
2150
+ if (!migrationGenerated) consola.log(" bun run db:make");
2136
2151
  consola.log(" bun run db:migrate");
2137
2152
  consola.log(" bun run db:seed");
2138
2153
  consola.log("");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-guren-app",
3
- "version": "1.21.1",
3
+ "version": "1.21.3",
4
4
  "description": "Scaffold a Guren app: a Bun-first fullstack TypeScript framework with Laravel-style conventions, Inertia.js + React, Drizzle ORM, and an agent harness for Claude Code and other coding agents.",
5
5
  "keywords": [
6
6
  "guren",
@@ -21,14 +21,14 @@
21
21
  "test": "bun test"
22
22
  },
23
23
  "dependencies": {
24
- "@guren/cli": "^2.36.1",
25
- "@guren/core": "^1.26.1",
26
- "@guren/orm": "^2.15.0",
24
+ "@guren/cli": "^2.36.3",
25
+ "@guren/core": "^1.27.0",
26
+ "@guren/orm": "^2.16.0",
27
27
  "drizzle-orm": "1.0.0-rc.4",
28
28
  "zod": "^4.5.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@guren/testing": "^1.14.4",
31
+ "@guren/testing": "^1.15.0",
32
32
  "bun-types": "^1.3.1",
33
33
  "drizzle-kit": "1.0.0-rc.4",
34
34
  "oxlint": "~1.81.0",
@@ -78,7 +78,7 @@ export interface ApiRoutes {
78
78
  'profile.update': {
79
79
  method: 'PUT'
80
80
  path: '/profile'
81
- body: { name: string; email: string; password?: string }
81
+ body: { name: string; email: string; password?: string; currentPassword?: string }
82
82
  }
83
83
  'register': {
84
84
  method: 'GET'
@@ -44,6 +44,7 @@ export const profileUpdateForm: RouteFormContract<'profile.update', 'PUT', '/pro
44
44
  name: { type: 'string', required: true, minLength: 1, maxLength: 120 },
45
45
  email: { type: 'string', required: true, format: 'email', minLength: 1 },
46
46
  password: { type: 'string', required: false },
47
+ currentPassword: { type: 'string', required: false },
47
48
  },
48
49
  }
49
50
 
@@ -56,7 +56,7 @@ export interface PagePropsMap {
56
56
  }
57
57
  'profile/Edit': {
58
58
  profile: { name: string; email: string }
59
- errors?: ValidationErrors<'name' | 'email' | 'password'>
59
+ errors?: ValidationErrors<'name' | 'email' | 'password' | 'currentPassword'>
60
60
  status?: string
61
61
  }
62
62
  }
@@ -151,7 +151,7 @@ declare module '@guren/core' {
151
151
  'posts.search': { body: { keywords: string[]; limit: number } }
152
152
  'posts.store': { body: { title: string; excerpt: string; body: string } }
153
153
  'posts.update': { body: { title: string; excerpt: string; body: string } }
154
- 'profile.update': { body: { name: string; email: string; password: string } }
154
+ 'profile.update': { body: { name: string; email: string; password: string; currentPassword: string } }
155
155
  'register.store': { body: { name: string; email: string; password: string; passwordConfirmation: string } }
156
156
  }
157
157
  }
@@ -10,12 +10,13 @@ bun install
10
10
  <!-- guren:container -->
11
11
  bun run db:up # start the __DATABASE_LABEL__ container
12
12
  <!-- /guren:container -->
13
- bun run db:make # generate the first migration from db/schema.ts
14
- bun run db:migrate
13
+ bun run db:migrate # create the users and posts tables
15
14
  bun run db:seed # demo@example.com / secret, plus two sample posts
16
15
  bun run dev
17
16
  ```
18
17
 
18
+ `create-guren-app` wrote the first migration into `db/migrations/` when it installed dependencies. If that folder holds no migration (the app was created with `--no-install`), run `bun run db:make` before `bun run db:migrate`.
19
+
19
20
  <!-- guren:container -->
20
21
  __DATABASE_LABEL__ runs in the container `docker-compose.yml` defines, and `DATABASE_URL` in `.env` points at it. `bun run db:down` stops it.
21
22
  <!-- /guren:container -->
@@ -23,8 +23,14 @@ export default class ProfileController extends Controller {
23
23
  return this.redirect('/login')
24
24
  }
25
25
 
26
- const { name, email, password } = this.validated('profile.update').body
27
- const emailChanged = email !== user.email
26
+ const { name, email, password, currentPassword } = this.validated('profile.update').body
27
+ // Normalized as the schema normalizes `email`: a stored address differing
28
+ // only in case or whitespace is the same mailbox, so not a credential change.
29
+ const emailChanged = email !== user.email.trim().toLowerCase()
30
+
31
+ if (emailChanged || password !== '') {
32
+ await this.currentPasswordCheck(user.email, currentPassword)
33
+ }
28
34
 
29
35
  if (emailChanged) {
30
36
  const existing = await User.where({ email })
@@ -40,9 +46,14 @@ export default class ProfileController extends Controller {
40
46
  ...(password ? { password } : {}),
41
47
  })
42
48
 
43
- const refreshed = await User.find(user.id)
44
- if (refreshed) {
45
- await this.auth.login(refreshed)
49
+ // Only after a password change: logging in again binds the session to the
50
+ // hash stored by then, which after any other update may be a password
51
+ // reset's, and would keep a session the reset meant to end.
52
+ if (password) {
53
+ const refreshed = await User.find(user.id)
54
+ if (refreshed) {
55
+ await this.auth.login(refreshed)
56
+ }
46
57
  }
47
58
 
48
59
  return this.inertia(pages.profile.Edit, {
@@ -50,4 +61,18 @@ export default class ProfileController extends Controller {
50
61
  status: 'Profile updated successfully.',
51
62
  }, { title: 'Profile' })
52
63
  }
64
+
65
+ // A session alone must not rotate the credentials that recover the account.
66
+ // An account with no password hash (created through OAuth) fails here too.
67
+ // Named: unqualified, a Bearer request resolves the token guard, whose
68
+ // validate() always throws.
69
+ private async currentPasswordCheck(email: string, currentPassword: string): Promise<void> {
70
+ if (currentPassword === '') {
71
+ throw ValidationException.withMessages({ currentPassword: 'Enter your current password to make this change.' })
72
+ }
73
+ const confirmed = await this.auth.guard('web').validate({ email, password: currentPassword })
74
+ if (!confirmed) {
75
+ throw ValidationException.withMessages({ currentPassword: 'The current password is incorrect.' })
76
+ }
77
+ }
53
78
  }
@@ -12,12 +12,14 @@ export const ProfileUpdateSchema = z.object({
12
12
  .min(1, 'Email is required.')
13
13
  .toLowerCase()
14
14
  .pipe(z.email('Enter a valid email address.')),
15
- // A default rather than a transform, so codegen types the parsed value as a string.
15
+ // Defaults rather than transforms, so codegen types the parsed values as strings.
16
16
  password: z
17
17
  .string()
18
18
  .trim()
19
19
  .default('')
20
20
  .refine((value) => value === '' || value.length >= 8, 'Password must be at least 8 characters.'),
21
+ // Untrimmed, as LoginSchema reads it: it is checked against the stored hash.
22
+ currentPassword: z.string().default(''),
21
23
  })
22
24
 
23
25
  export type ProfileUpdateInput = z.infer<typeof ProfileUpdateSchema>
@@ -9,12 +9,12 @@ import type { ValidationErrors } from '@guren/core'
9
9
 
10
10
  interface Props {
11
11
  profile: { name: string; email: string }
12
- errors?: ValidationErrors<'name' | 'email' | 'password'>
12
+ errors?: ValidationErrors<'name' | 'email' | 'password' | 'currentPassword'>
13
13
  status?: string
14
14
  }
15
15
 
16
16
  export default function ProfileEdit({ profile, status }: Props) {
17
- const form = useRouteForm(profileUpdateForm, { name: profile.name, email: profile.email, password: '' })
17
+ const form = useRouteForm(profileUpdateForm, { name: profile.name, email: profile.email, password: '', currentPassword: '' })
18
18
 
19
19
  return (
20
20
  <Layout>
@@ -36,6 +36,7 @@ export default function ProfileEdit({ profile, status }: Props) {
36
36
  <Field form={form} name="name" />
37
37
  <Field form={form} name="email" />
38
38
  <Field form={form} name="password" as="password" label="New password" />
39
+ <Field form={form} name="currentPassword" as="password" hint="Required to change your email or password." />
39
40
  <Button type="submit" disabled={form.processing} block>
40
41
  Save changes
41
42
  </Button>
@@ -3,7 +3,7 @@ import LoginController from '../app/Http/Controllers/Auth/LoginController.js'
3
3
  import RegisterController from '../app/Http/Controllers/Auth/RegisterController.js'
4
4
  import DashboardController from '../app/Http/Controllers/DashboardController.js'
5
5
  import ProfileController from '../app/Http/Controllers/ProfileController.js'
6
- import { throttleLogin, throttleRegistration } from '../app/Http/Middleware/AuthThrottle.js'
6
+ import { throttleLogin, throttleProfileUpdate, throttleRegistration } from '../app/Http/Middleware/AuthThrottle.js'
7
7
  import { LoginSchema } from '../app/Http/Validators/LoginValidator.js'
8
8
  import { ProfileUpdateSchema } from '../app/Http/Validators/ProfileValidator.js'
9
9
  import { RegisterSchema } from '../app/Http/Validators/RegisterValidator.js'
@@ -21,6 +21,6 @@ export function registerAuthRoutes(router: Router<'auth' | 'guest'>): void {
21
21
  authed.post('/logout', [LoginController, 'destroy']).name('logout')
22
22
  authed.get('/dashboard', [DashboardController, 'index']).name('dashboard')
23
23
  authed.get('/profile', [ProfileController, 'edit']).name('profile.edit')
24
- authed.put('/profile', { name: 'profile.update', body: ProfileUpdateSchema }, [ProfileController, 'update'])
24
+ authed.put('/profile', { name: 'profile.update', body: ProfileUpdateSchema, middlewares: [throttleProfileUpdate] }, [ProfileController, 'update'])
25
25
  })
26
26
  }
@@ -22,10 +22,10 @@
22
22
  "db:seed": "bunx guren db:seed"
23
23
  },
24
24
  "dependencies": {
25
- "@guren/cli": "^2.36.1",
26
- "@guren/core": "^1.26.1",
25
+ "@guren/cli": "^2.36.3",
26
+ "@guren/core": "^1.27.0",
27
27
  "@guren/inertia-client": "^1.4.0",
28
- "@guren/orm": "^2.15.0",
28
+ "@guren/orm": "^2.16.0",
29
29
  "@inertiajs/react": "^3.11.0",
30
30
  "drizzle-orm": "1.0.0-rc.4",
31
31
  "react": "^19.0.0",
@@ -33,7 +33,7 @@
33
33
  "zod": "^4.5.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@guren/testing": "^1.14.4",
36
+ "@guren/testing": "^1.15.0",
37
37
  "@tailwindcss/vite": "^4.2.2",
38
38
  "@types/react": "^19.0.0",
39
39
  "@types/react-dom": "^19.0.0",