create-guren-app 1.21.0 → 1.21.2
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/package.json +1 -1
- package/templates/api-only/package.json +2 -2
- package/templates/blog/.guren/api-client.gen.ts +1 -1
- package/templates/blog/.guren/forms.gen.ts +1 -0
- package/templates/blog/.guren/pages.gen.ts +1 -1
- package/templates/blog/.guren/routes.gen.ts +1 -1
- package/templates/blog/app/Http/Controllers/ProfileController.ts +30 -5
- package/templates/blog/app/Http/Validators/ProfileValidator.ts +3 -1
- package/templates/blog/resources/js/pages/profile/Edit.tsx +3 -2
- package/templates/blog/routes/auth.ts +2 -2
- package/templates/default/package.json +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-guren-app",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.2",
|
|
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",
|
|
@@ -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
|
}
|
|
@@ -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
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
//
|
|
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.
|
|
25
|
+
"@guren/cli": "^2.36.2",
|
|
26
26
|
"@guren/core": "^1.26.1",
|
|
27
27
|
"@guren/inertia-client": "^1.4.0",
|
|
28
|
-
"@guren/orm": "^2.15.
|
|
28
|
+
"@guren/orm": "^2.15.1",
|
|
29
29
|
"@inertiajs/react": "^3.11.0",
|
|
30
30
|
"drizzle-orm": "1.0.0-rc.4",
|
|
31
31
|
"react": "^19.0.0",
|