@humanonlyweb/create-nuxtflare 0.2.1 → 0.2.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 +17 -17
- package/dist/template/CLAUDE.md +1 -0
- package/dist/template/app/composables/use-account.ts +196 -0
- package/dist/template/app/composables/use-admin-login.ts +27 -0
- package/dist/template/app/composables/use-auth.ts +94 -295
- package/dist/template/app/composables/use-token-confirm.ts +52 -0
- package/dist/template/app/pages/account.vue +80 -39
- package/dist/template/app/pages/admin/login.vue +8 -23
- package/dist/template/app/pages/forgot-password.vue +9 -4
- package/dist/template/app/pages/login.vue +29 -10
- package/dist/template/app/pages/register.vue +18 -6
- package/dist/template/app/pages/reset/[token].vue +8 -5
- package/dist/template/nuxt.config.ts +6 -1
- package/dist/template/package.json +1 -0
- package/dist/template/shared/utils/schema-validation.ts +24 -3
- package/package.json +17 -17
package/dist/cli.js
CHANGED
|
@@ -6,30 +6,26 @@ import { basename as basename2, resolve as resolve2 } from "node:path";
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@humanonlyweb/create-nuxtflare",
|
|
9
|
-
version: "0.2.
|
|
9
|
+
version: "0.2.3",
|
|
10
10
|
description: "Scaffold a Nuxt 5 + Cloudflare Workers + D1 + Effect v4 app with explicit auth, TOTP 2FA, and admin.",
|
|
11
|
-
license: "MIT",
|
|
12
|
-
repository: {
|
|
13
|
-
type: "git",
|
|
14
|
-
url: "git+https://github.com/humanonlyweb/nuxtflare.git"
|
|
15
|
-
},
|
|
16
|
-
homepage: "https://github.com/humanonlyweb/nuxtflare#readme",
|
|
17
|
-
bugs: {
|
|
18
|
-
url: "https://github.com/humanonlyweb/nuxtflare/issues"
|
|
19
|
-
},
|
|
20
11
|
keywords: [
|
|
21
|
-
"nuxt",
|
|
22
|
-
"nuxt5",
|
|
23
12
|
"cloudflare",
|
|
24
13
|
"cloudflare-workers",
|
|
14
|
+
"create",
|
|
25
15
|
"d1",
|
|
26
16
|
"effect",
|
|
27
|
-
"
|
|
28
|
-
"
|
|
17
|
+
"nuxt",
|
|
18
|
+
"nuxt5",
|
|
19
|
+
"starter"
|
|
29
20
|
],
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
homepage: "https://github.com/humanonlyweb/nuxtflare#readme",
|
|
22
|
+
bugs: {
|
|
23
|
+
url: "https://github.com/humanonlyweb/nuxtflare/issues"
|
|
24
|
+
},
|
|
25
|
+
license: "MIT",
|
|
26
|
+
repository: {
|
|
27
|
+
type: "git",
|
|
28
|
+
url: "git+https://github.com/humanonlyweb/nuxtflare.git"
|
|
33
29
|
},
|
|
34
30
|
bin: {
|
|
35
31
|
"create-nuxtflare": "./dist/cli.js",
|
|
@@ -38,6 +34,10 @@ var package_default = {
|
|
|
38
34
|
files: [
|
|
39
35
|
"dist"
|
|
40
36
|
],
|
|
37
|
+
type: "module",
|
|
38
|
+
publishConfig: {
|
|
39
|
+
access: "public"
|
|
40
|
+
},
|
|
41
41
|
scripts: {
|
|
42
42
|
build: "bun scripts/build.ts",
|
|
43
43
|
test: "bun test src/scaffold.test.ts",
|
package/dist/template/CLAUDE.md
CHANGED
|
@@ -38,6 +38,7 @@ Never rely on callers "remembering" a rule, ordering assumption, or hidden conve
|
|
|
38
38
|
|
|
39
39
|
- **Comments**: No useless or restating comments — only add a comment when it explains a non-obvious reason, constraint, or trade-off that genuinely improves understanding.
|
|
40
40
|
- **Vue components**: Component filenames use `kebab-case` (e.g. `app/components/qr-code.vue`, `app/components/totp-setup.vue`).
|
|
41
|
+
- **UI library**: For `@humanonlyweb/ui`, read `node_modules/@humanonlyweb/ui/dist/docs/README.md` before using a component. It indexes a page per component: props, events, slots, and styling hooks.
|
|
41
42
|
- **Typed errors only**: Services fail with tagged errors from `shared/domain/errors.ts` or `server/utils/errors.ts`. Unexpected defects become a bare 500.
|
|
42
43
|
- **D1 safety**: Bound parameters are capped at 100 per statement — use `chunked` for variable-length `IN (...)` lists. Pure `SELECT` queries retry transient D1 resets; writes never retry automatically.
|
|
43
44
|
- **Secrets**: Come from Nuxt runtime config (`NUXT_*`), wrapped in `Redacted` inside `AppConfig`. Never read secrets off Cloudflare `env`.
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
import { ChangeEmailFormSchema, DeleteAccountFormSchema, ProfileFormSchema, SetPasswordFormSchema } from '#shared/utils/schema-validation'
|
|
4
|
+
import { fieldErrors, problemOf } from '~/utils/api-error'
|
|
5
|
+
|
|
6
|
+
const mapFields = fieldErrors()
|
|
7
|
+
type FormElementRef = Readonly<Ref<HTMLElement | null>>
|
|
8
|
+
|
|
9
|
+
export const useAccount = (
|
|
10
|
+
options: {
|
|
11
|
+
readonly profileFormRef?: FormElementRef
|
|
12
|
+
readonly passwordFormRef?: FormElementRef
|
|
13
|
+
readonly emailFormRef?: FormElementRef
|
|
14
|
+
readonly deleteFormRef?: FormElementRef
|
|
15
|
+
} = {},
|
|
16
|
+
) => {
|
|
17
|
+
const features = useFeatures()
|
|
18
|
+
const { clear, fetch: refreshSession, user: sessionUser } = useUserSession()
|
|
19
|
+
const meFetch = useMe()
|
|
20
|
+
const { data: me, refresh: refreshMe } = meFetch
|
|
21
|
+
|
|
22
|
+
const canUseVerifiedActions = computed(() => Boolean(me.value && (!features.emailVerificationRequired || me.value.emailStatus === 'verified')))
|
|
23
|
+
|
|
24
|
+
const initiallyVerified = Boolean(!features.emailVerificationRequired || sessionUser.value?.verified)
|
|
25
|
+
const sessionsFetch = useFetch('/api/account/sessions', {
|
|
26
|
+
immediate: initiallyVerified,
|
|
27
|
+
default: () => ({ sessions: [] }),
|
|
28
|
+
})
|
|
29
|
+
const { data: sessionList, refresh: refreshSessions } = sessionsFetch
|
|
30
|
+
|
|
31
|
+
const actionBusy = ref(false)
|
|
32
|
+
const notice = ref('')
|
|
33
|
+
const errorMessage = ref('')
|
|
34
|
+
|
|
35
|
+
const onFormError = (error: unknown) => {
|
|
36
|
+
if (!mapFields(error)) errorMessage.value = problemOf(error).message
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const runAction = async (work: () => Promise<void>, successMessage?: string) => {
|
|
40
|
+
errorMessage.value = ''
|
|
41
|
+
notice.value = ''
|
|
42
|
+
actionBusy.value = true
|
|
43
|
+
try {
|
|
44
|
+
await work()
|
|
45
|
+
if (successMessage) notice.value = successMessage
|
|
46
|
+
} catch (error) {
|
|
47
|
+
errorMessage.value = problemOf(error).message
|
|
48
|
+
} finally {
|
|
49
|
+
actionBusy.value = false
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const profile = useForm({
|
|
54
|
+
schema: ProfileFormSchema,
|
|
55
|
+
initialValues: { username: me.value?.username ?? '' },
|
|
56
|
+
formRef: options.profileFormRef,
|
|
57
|
+
mapError: mapFields,
|
|
58
|
+
onSubmit: async (values) => {
|
|
59
|
+
errorMessage.value = ''
|
|
60
|
+
notice.value = ''
|
|
61
|
+
const updated = await $fetch('/api/account', { method: 'PATCH', body: values })
|
|
62
|
+
profile.setValues({ username: updated.username })
|
|
63
|
+
await Promise.all([refreshMe(), refreshSession()])
|
|
64
|
+
notice.value = 'Username updated.'
|
|
65
|
+
},
|
|
66
|
+
onError: onFormError,
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
watch(
|
|
70
|
+
me,
|
|
71
|
+
(next) => {
|
|
72
|
+
if (next && !profile.isDirty.value) profile.setValues({ username: next.username })
|
|
73
|
+
},
|
|
74
|
+
{ immediate: true },
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
watch(canUseVerifiedActions, (verified) => {
|
|
78
|
+
if (verified) void refreshSessions()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const passwordForm = useForm({
|
|
82
|
+
schema: SetPasswordFormSchema,
|
|
83
|
+
initialValues: { currentPassword: '', newPassword: '', code: '' },
|
|
84
|
+
formRef: options.passwordFormRef,
|
|
85
|
+
mapError: mapFields,
|
|
86
|
+
onSubmit: async (values) => {
|
|
87
|
+
errorMessage.value = ''
|
|
88
|
+
notice.value = ''
|
|
89
|
+
const hadPassword = Boolean(me.value?.hasPassword)
|
|
90
|
+
await $fetch('/api/account/password', {
|
|
91
|
+
method: 'POST',
|
|
92
|
+
body: {
|
|
93
|
+
...(hadPassword && values.currentPassword ? { currentPassword: values.currentPassword } : {}),
|
|
94
|
+
newPassword: values.newPassword,
|
|
95
|
+
...(values.code ? { code: values.code } : {}),
|
|
96
|
+
},
|
|
97
|
+
})
|
|
98
|
+
passwordForm.reset()
|
|
99
|
+
await Promise.all([refreshMe(), refreshSessions()])
|
|
100
|
+
notice.value = hadPassword ? 'Password updated and other sessions signed out.' : 'Password set.'
|
|
101
|
+
},
|
|
102
|
+
onError: onFormError,
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const emailForm = useForm({
|
|
106
|
+
schema: ChangeEmailFormSchema,
|
|
107
|
+
initialValues: { email: '', password: '', code: '' },
|
|
108
|
+
formRef: options.emailFormRef,
|
|
109
|
+
mapError: mapFields,
|
|
110
|
+
onSubmit: async (values) => {
|
|
111
|
+
errorMessage.value = ''
|
|
112
|
+
notice.value = ''
|
|
113
|
+
await $fetch('/api/account/email', {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
body: {
|
|
116
|
+
email: values.email,
|
|
117
|
+
password: values.password,
|
|
118
|
+
...(values.code ? { code: values.code } : {}),
|
|
119
|
+
},
|
|
120
|
+
})
|
|
121
|
+
emailForm.reset()
|
|
122
|
+
await refreshMe()
|
|
123
|
+
notice.value = 'Check your new email address for a confirmation link.'
|
|
124
|
+
},
|
|
125
|
+
onError: onFormError,
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
const deleteForm = useForm({
|
|
129
|
+
schema: DeleteAccountFormSchema,
|
|
130
|
+
initialValues: { confirm: '', password: '', code: '' },
|
|
131
|
+
formRef: options.deleteFormRef,
|
|
132
|
+
mapError: mapFields,
|
|
133
|
+
onSubmit: async (values) => {
|
|
134
|
+
errorMessage.value = ''
|
|
135
|
+
notice.value = ''
|
|
136
|
+
await $fetch('/api/account', {
|
|
137
|
+
method: 'DELETE',
|
|
138
|
+
body: {
|
|
139
|
+
confirm: values.confirm,
|
|
140
|
+
...(values.password ? { password: values.password } : {}),
|
|
141
|
+
...(values.code ? { code: values.code } : {}),
|
|
142
|
+
},
|
|
143
|
+
})
|
|
144
|
+
await clear()
|
|
145
|
+
await navigateTo('/login')
|
|
146
|
+
},
|
|
147
|
+
onError: onFormError,
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
const signOut = () =>
|
|
151
|
+
runAction(async () => {
|
|
152
|
+
await $fetch('/api/auth/logout', { method: 'POST' })
|
|
153
|
+
await clear()
|
|
154
|
+
await navigateTo('/login')
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const signOutEverywhere = () =>
|
|
158
|
+
runAction(async () => {
|
|
159
|
+
await $fetch('/api/auth/logout-everywhere', { method: 'POST' })
|
|
160
|
+
await clear()
|
|
161
|
+
await navigateTo('/login')
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
const resendVerification = () =>
|
|
165
|
+
runAction(async () => {
|
|
166
|
+
await $fetch('/api/auth/verify/send', { method: 'POST' })
|
|
167
|
+
}, 'Verification email sent.')
|
|
168
|
+
|
|
169
|
+
const cancelEmailChange = () =>
|
|
170
|
+
runAction(async () => {
|
|
171
|
+
await $fetch('/api/account/email', { method: 'DELETE' })
|
|
172
|
+
await refreshMe()
|
|
173
|
+
}, 'Pending email change cancelled.')
|
|
174
|
+
|
|
175
|
+
const ready = Promise.all([meFetch, sessionsFetch]).then(() => undefined)
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
ready,
|
|
179
|
+
me,
|
|
180
|
+
features,
|
|
181
|
+
canUseVerifiedActions,
|
|
182
|
+
sessionList,
|
|
183
|
+
profile,
|
|
184
|
+
passwordForm,
|
|
185
|
+
emailForm,
|
|
186
|
+
deleteForm,
|
|
187
|
+
actionBusy,
|
|
188
|
+
notice,
|
|
189
|
+
errorMessage,
|
|
190
|
+
refreshSessions,
|
|
191
|
+
signOut,
|
|
192
|
+
signOutEverywhere,
|
|
193
|
+
resendVerification,
|
|
194
|
+
cancelEmailChange,
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
import { AdminLoginFormSchema } from '#shared/utils/schema-validation'
|
|
4
|
+
import { fieldErrors, problemOf } from '~/utils/api-error'
|
|
5
|
+
|
|
6
|
+
const mapFields = fieldErrors()
|
|
7
|
+
|
|
8
|
+
export const useAdminLogin = (options: { readonly formRef?: Readonly<Ref<HTMLElement | null>> } = {}) => {
|
|
9
|
+
const errorMessage = ref('')
|
|
10
|
+
|
|
11
|
+
const formState = useForm({
|
|
12
|
+
schema: AdminLoginFormSchema,
|
|
13
|
+
initialValues: { email: '', password: '' },
|
|
14
|
+
formRef: options.formRef,
|
|
15
|
+
mapError: mapFields,
|
|
16
|
+
onSubmit: async (values) => {
|
|
17
|
+
errorMessage.value = ''
|
|
18
|
+
await $fetch('/api/admin/session', { method: 'POST', body: values })
|
|
19
|
+
await navigateTo('/admin')
|
|
20
|
+
},
|
|
21
|
+
onError: (error) => {
|
|
22
|
+
if (!mapFields(error)) errorMessage.value = problemOf(error).message
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
return { ...formState, errorMessage }
|
|
27
|
+
}
|