@humanonlyweb/create-nuxtflare 0.2.4 → 0.2.6
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/README.md +0 -22
- package/dist/cli.js +2 -1
- package/dist/template/.github/workflows/ci.yml +19 -14
- package/dist/template/CLAUDE.md +3 -3
- package/dist/template/app/components/totp-setup.vue +18 -13
- package/dist/template/app/composables/use-account.ts +7 -5
- package/dist/template/app/composables/use-auth.ts +11 -7
- package/dist/template/app/pages/account.vue +2 -1
- package/dist/template/nuxt.config.ts +5 -2
- package/dist/template/package.json +9 -8
- package/dist/template/public/_headers +6 -0
- package/dist/template/server/api/account/index.delete.ts +1 -1
- package/dist/template/server/api/auth/logout-everywhere.post.ts +1 -1
- package/dist/template/server/api/auth/logout.post.ts +3 -11
- package/dist/template/server/api/auth/register.post.ts +11 -3
- package/dist/template/server/api/auth/verify/send.post.ts +11 -4
- package/dist/template/server/app/identity/lockout.ts +10 -5
- package/dist/template/server/app/identity/service.ts +50 -16
- package/dist/template/server/app/identity/sessions.ts +2 -1
- package/dist/template/server/app/identity/totp.test.ts +1 -0
- package/dist/template/server/app/identity/totp.ts +16 -6
- package/dist/template/server/app/identity/verification.ts +29 -7
- package/dist/template/server/core/app-layer.ts +3 -2
- package/dist/template/server/core/db/atomic-d1.ts +12 -6
- package/dist/template/server/core/db/atomic.ts +36 -25
- package/dist/template/server/core/db/migrations.ts +11 -0
- package/dist/template/server/core/db/migrator.ts +0 -10
- package/dist/template/server/core/db/session-d1.ts +56 -0
- package/dist/template/server/core/db/session.test.ts +97 -0
- package/dist/template/server/core/db/session.ts +171 -0
- package/dist/template/server/core/http/handle.ts +13 -3
- package/dist/template/server/core/http/session.ts +49 -1
- package/dist/template/server/core/platform/app-config.ts +2 -0
- package/dist/template/server/core/platform/database.ts +39 -22
- package/dist/template/server/middleware/01-user-session.ts +11 -2
- package/dist/template/server/plugins/page-csp.ts +1 -1
- package/dist/template/server/plugins/sessions.ts +16 -4
- package/dist/template/server/test/kit.ts +4 -0
- package/dist/template/shared/utils/auth.ts +1 -0
- package/dist/template/wrangler.json +3 -0
- package/package.json +1 -1
- /package/dist/template/app/components/{qr-code.vue → qr-code.client.vue} +0 -0
package/README.md
CHANGED
|
@@ -23,28 +23,6 @@ bun create @humanonlyweb/nuxtflare@latest my-project -- -y \
|
|
|
23
23
|
--github
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
### Local (before publishing)
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
bun bin/cli.ts my-project
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Publishing to npm
|
|
33
|
-
|
|
34
|
-
First release (creates the package on npm so Trusted Publishing can be linked):
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
npm login
|
|
38
|
-
bun publish --access public
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Then configure **Trusted Publisher** on npmjs.com pointing at `humanonlyweb / nuxtflare / release.yml`. Future releases publish automatically with provenance when you push a matching `v*` tag:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
npm version patch # or minor / major
|
|
45
|
-
git push --follow-tags
|
|
46
|
-
```
|
|
47
|
-
|
|
48
26
|
## What's included
|
|
49
27
|
|
|
50
28
|
- **Cloudflare Workers + D1 + KV + Durable Objects + Email** behind Effect v4 `Context.Service` ports (`Database` with read-only transient retry, `AtomicBatch` with `runGuarded` + `assertPreviousChanged`, race-safe `MigratorLive`, `RateLimitCounter` sliding-window DO, `Pii` AES-256-GCM field encryption with key rotation + blind index, `Seal`, `Tokens`, `Turnstile`, `Mailer`, `EmailAssets`).
|
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ 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.6",
|
|
10
10
|
description: "Scaffold a Nuxt 5 + Cloudflare Workers + D1 + Effect v4 app with explicit auth, TOTP 2FA, and admin.",
|
|
11
11
|
keywords: [
|
|
12
12
|
"cloudflare",
|
|
@@ -155,6 +155,7 @@ var scaffold = (options) => {
|
|
|
155
155
|
} as const`).replace(`title: 'Nuxtflare App'`, `title: '${options.appName.replaceAll("'", "\\'")}'`).replace(`appUrl: 'https://example.com'`, `appUrl: 'https://${options.domain}'`).replace(`adminEmails: 'admin@example.test'`, `adminEmails: 'admin@${options.slug}.test'`).replace(`appName: text('Nuxtflare App'`, `appName: text('${options.appName.replaceAll("'", "\\'")}'`).replace(`mailFrom: text('Nuxtflare App <no-reply@example.com>'`, `mailFrom: text('${options.appName.replaceAll("'", "\\'")} <no-reply@${options.domain}>'`).replace(`name: 'app-session'`, `name: '${options.cookiePrefix}-session'`));
|
|
156
156
|
replaceInFile(join(targetDir, "shared/utils/admin.ts"), (content) => content.replace(`ADMIN_COOKIE = 'app_admin'`, `ADMIN_COOKIE = '${options.cookiePrefix}_admin'`));
|
|
157
157
|
replaceInFile(join(targetDir, "server/core/http/handle.ts"), (content) => content.replace(`TOTP_CHALLENGE_COOKIE = 'app_totp'`, `TOTP_CHALLENGE_COOKIE = '${options.cookiePrefix}_totp'`));
|
|
158
|
+
replaceInFile(join(targetDir, "server/core/http/session.ts"), (content) => content.replace(`D1_BOOKMARK_COOKIE = 'app_d1_bm'`, `D1_BOOKMARK_COOKIE = '${options.cookiePrefix}_d1_bm'`));
|
|
158
159
|
replaceInFile(join(targetDir, "app/composables/use-auth.ts"), (content) => content.replace(`app_next=`, `${options.cookiePrefix}_next=`));
|
|
159
160
|
replaceInFile(join(targetDir, "server/routes/auth/google.get.ts"), (content) => content.replaceAll(`'app_next'`, `'${options.cookiePrefix}_next'`));
|
|
160
161
|
replaceInFile(join(targetDir, "server/routes/auth/github.get.ts"), (content) => content.replaceAll(`'app_next'`, `'${options.cookiePrefix}_next'`).replace(`'nuxtflare-oauth'`, `'${options.slug}-oauth'`));
|
|
@@ -44,21 +44,20 @@ jobs:
|
|
|
44
44
|
- name: Install dependencies
|
|
45
45
|
run: bun install --frozen-lockfile
|
|
46
46
|
|
|
47
|
-
- name: Type-check
|
|
48
|
-
run: bun run typecheck
|
|
49
|
-
|
|
50
|
-
- name: Lint
|
|
51
|
-
run: bun run lint
|
|
52
|
-
|
|
53
|
-
- name: Format
|
|
54
|
-
run: bun run fmt:check
|
|
55
|
-
|
|
56
|
-
- name: Test
|
|
57
|
-
run: bun run test
|
|
47
|
+
- name: Type-check, lint, format, and test
|
|
48
|
+
run: bun run --parallel typecheck:tsc lint fmt:check test
|
|
58
49
|
|
|
59
50
|
- name: Build
|
|
60
51
|
run: bun run build
|
|
61
52
|
|
|
53
|
+
- name: Upload build output
|
|
54
|
+
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
|
|
55
|
+
uses: actions/upload-artifact@v7
|
|
56
|
+
with:
|
|
57
|
+
name: worker-output
|
|
58
|
+
path: .output
|
|
59
|
+
retention-days: 1
|
|
60
|
+
|
|
62
61
|
deploy:
|
|
63
62
|
name: Deploy production
|
|
64
63
|
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
|
|
@@ -89,10 +88,16 @@ jobs:
|
|
|
89
88
|
${{ runner.os }}-${{ runner.arch }}-bun-
|
|
90
89
|
|
|
91
90
|
- name: Install dependencies
|
|
92
|
-
run: bun install --frozen-lockfile
|
|
91
|
+
run: bun install --frozen-lockfile --ignore-scripts
|
|
92
|
+
|
|
93
|
+
- name: Download build output
|
|
94
|
+
uses: actions/download-artifact@v8
|
|
95
|
+
with:
|
|
96
|
+
name: worker-output
|
|
97
|
+
path: .output
|
|
93
98
|
|
|
94
99
|
- name: Apply D1 migrations
|
|
95
100
|
run: bun run db:migrate:remote
|
|
96
101
|
|
|
97
|
-
- name:
|
|
98
|
-
run:
|
|
102
|
+
- name: Deploy the Worker
|
|
103
|
+
run: bunx wrangler deploy --config .output/server/wrangler.json
|
package/dist/template/CLAUDE.md
CHANGED
|
@@ -4,7 +4,7 @@ Nuxt 5 / Nitro on one Cloudflare Worker, D1 via `useDatabase()` (no ORM), Effect
|
|
|
4
4
|
|
|
5
5
|
## Architecture
|
|
6
6
|
|
|
7
|
-
- `server/core/`: Platform ports (`Database`, `AtomicBatch`, `Kv`, `Pii`, `Seal`, `Tokens`, `PasswordHasher`, `IdGenerator`, `RateLimiter`, `Turnstile`, `Mailer`, `EmailAssets`), HTTP handlers (`handlePublic`, `handleAuthed`, `handleAdmin`), migrations, and `app-layer.ts`.
|
|
7
|
+
- `server/core/`: Platform ports (`Database`, `AtomicBatch`, `DbSession`, `Kv`, `Pii`, `Seal`, `Tokens`, `PasswordHasher`, `IdGenerator`, `RateLimiter`, `Turnstile`, `Mailer`, `EmailAssets`), HTTP handlers (`handlePublic`, `handleAuthed`, `handleAdmin`), migrations, and `app-layer.ts`.
|
|
8
8
|
- `server/app/`: Domain features (`identity/`, `notifications/`, `admin/`, `maintenance/`, plus your own features) composed once in `server/app/features.ts`.
|
|
9
9
|
- `server/tasks/`: Nitro scheduled tasks (`cleanup.ts`, wired to Cloudflare Cron Triggers via `nitro.scheduledTasks`).
|
|
10
10
|
- `server/assets/email/`: Nitro server-asset HTML layout and blocks rendered by `EmailRenderer` (both HTML and plain text). Preview all templates in dev at `/emails`.
|
|
@@ -37,9 +37,9 @@ Never rely on callers "remembering" a rule, ordering assumption, or hidden conve
|
|
|
37
37
|
## Conventions
|
|
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
|
-
- **Vue components**: Component filenames use `kebab-case` (e.g. `app/components/qr-code.vue`, `app/components/totp-setup.vue`).
|
|
40
|
+
- **Vue components**: Component filenames use `kebab-case` (e.g. `app/components/qr-code.client.vue`, `app/components/totp-setup.vue`).
|
|
41
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.
|
|
42
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.
|
|
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
|
+
- **D1 safety & replication**: 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. Single-region D1 uses Smart Placement (`placement.mode = "smart"` in `wrangler.json`). To use global D1 Read Replication instead, enable `d1Sessions: true` (`NUXT_D1_SESSIONS=true`) — all HTTP routes automatically propagate per-client bookmarks via `DbSession` (override per route with `dbSession: 'first-primary' | false`, or wrap any Effect with `withDbSession`) and you can remove `placement` from `wrangler.json`.
|
|
44
44
|
- **Secrets**: Come from Nuxt runtime config (`NUXT_*`), wrapped in `Redacted` inside `AppConfig`. Never read secrets off Cloudflare `env`.
|
|
45
45
|
- **Testing**: `server/test/kit.ts` boots real SQLite (`node:sqlite` via `db0`) with all migrations applied and fast in-memory fakes for Cloudflare bindings. Keep `bun run check` green.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import type {
|
|
2
|
+
import type { TotpStatus } from '#shared/utils/auth'
|
|
3
3
|
|
|
4
4
|
import { problemOf } from '~/utils/api-error'
|
|
5
5
|
|
|
@@ -8,11 +8,16 @@ type UiStep =
|
|
|
8
8
|
| { readonly kind: 'enrolling'; readonly secret: string; readonly uri: string }
|
|
9
9
|
| { readonly kind: 'recovery'; readonly codes: ReadonlyArray<string> }
|
|
10
10
|
|
|
11
|
+
const props = defineProps<{
|
|
12
|
+
readonly status: TotpStatus
|
|
13
|
+
readonly recoveryCodesLeft: number
|
|
14
|
+
}>()
|
|
15
|
+
|
|
16
|
+
const emit = defineEmits<{
|
|
17
|
+
readonly updated: []
|
|
18
|
+
}>()
|
|
19
|
+
|
|
11
20
|
const features = useFeatures()
|
|
12
|
-
const { data: security, refresh } = await useFetch<TotpSecurityView | null>('/api/account/totp', {
|
|
13
|
-
immediate: features.totp,
|
|
14
|
-
default: () => null,
|
|
15
|
-
})
|
|
16
21
|
|
|
17
22
|
const step = ref<UiStep>({ kind: 'idle' })
|
|
18
23
|
const password = ref('')
|
|
@@ -27,7 +32,7 @@ const start = async () => {
|
|
|
27
32
|
const setup = await $fetch('/api/account/totp/start', { method: 'POST', body: { password: password.value } })
|
|
28
33
|
password.value = ''
|
|
29
34
|
step.value = { kind: 'enrolling', secret: setup.secret, uri: setup.uri }
|
|
30
|
-
|
|
35
|
+
emit('updated')
|
|
31
36
|
} catch (error) {
|
|
32
37
|
errorMessage.value = problemOf(error).message
|
|
33
38
|
} finally {
|
|
@@ -42,7 +47,7 @@ const confirm = async () => {
|
|
|
42
47
|
const result = await $fetch('/api/account/totp/confirm', { method: 'POST', body: { code: code.value } })
|
|
43
48
|
code.value = ''
|
|
44
49
|
step.value = { kind: 'recovery', codes: result.recoveryCodes }
|
|
45
|
-
|
|
50
|
+
emit('updated')
|
|
46
51
|
} catch (error) {
|
|
47
52
|
errorMessage.value = problemOf(error).message
|
|
48
53
|
} finally {
|
|
@@ -57,7 +62,7 @@ const cancel = async () => {
|
|
|
57
62
|
await $fetch('/api/account/totp/cancel', { method: 'POST' })
|
|
58
63
|
code.value = ''
|
|
59
64
|
step.value = { kind: 'idle' }
|
|
60
|
-
|
|
65
|
+
emit('updated')
|
|
61
66
|
} catch (error) {
|
|
62
67
|
errorMessage.value = problemOf(error).message
|
|
63
68
|
} finally {
|
|
@@ -73,7 +78,7 @@ const disable = async () => {
|
|
|
73
78
|
password.value = ''
|
|
74
79
|
code.value = ''
|
|
75
80
|
step.value = { kind: 'idle' }
|
|
76
|
-
|
|
81
|
+
emit('updated')
|
|
77
82
|
} catch (error) {
|
|
78
83
|
errorMessage.value = problemOf(error).message
|
|
79
84
|
} finally {
|
|
@@ -83,7 +88,7 @@ const disable = async () => {
|
|
|
83
88
|
</script>
|
|
84
89
|
|
|
85
90
|
<template>
|
|
86
|
-
<section v-if="features.totp
|
|
91
|
+
<section v-if="features.totp" class="totp">
|
|
87
92
|
<h2>Two-factor authentication</h2>
|
|
88
93
|
<p v-if="errorMessage" role="alert">{{ errorMessage }}</p>
|
|
89
94
|
|
|
@@ -100,7 +105,7 @@ const disable = async () => {
|
|
|
100
105
|
<div v-else-if="step.kind === 'enrolling'">
|
|
101
106
|
<p>Scan this QR code with your authenticator app, or enter the key manually:</p>
|
|
102
107
|
<div class="totp__qr">
|
|
103
|
-
<
|
|
108
|
+
<LazyQrCode :value="step.uri" label="Authenticator setup QR code" />
|
|
104
109
|
</div>
|
|
105
110
|
<p>
|
|
106
111
|
<code>{{ step.secret }}</code>
|
|
@@ -115,8 +120,8 @@ const disable = async () => {
|
|
|
115
120
|
</form>
|
|
116
121
|
</div>
|
|
117
122
|
|
|
118
|
-
<div v-else-if="
|
|
119
|
-
<p>Two-factor authentication is enabled ({{
|
|
123
|
+
<div v-else-if="props.status === 'enabled'">
|
|
124
|
+
<p>Two-factor authentication is enabled ({{ props.recoveryCodesLeft }} recovery codes left).</p>
|
|
120
125
|
<form @submit.prevent="disable">
|
|
121
126
|
<label>
|
|
122
127
|
Current password
|
|
@@ -15,7 +15,7 @@ export const useAccount = (
|
|
|
15
15
|
} = {},
|
|
16
16
|
) => {
|
|
17
17
|
const features = useFeatures()
|
|
18
|
-
const {
|
|
18
|
+
const { session, user: sessionUser } = useUserSession()
|
|
19
19
|
const meFetch = useMe()
|
|
20
20
|
const { data: me, refresh: refreshMe } = meFetch
|
|
21
21
|
|
|
@@ -60,7 +60,8 @@ export const useAccount = (
|
|
|
60
60
|
notice.value = ''
|
|
61
61
|
const updated = await $fetch('/api/account', { method: 'PATCH', body: values })
|
|
62
62
|
profile.setValues({ username: updated.username })
|
|
63
|
-
|
|
63
|
+
if (me.value) me.value = { ...me.value, username: updated.username }
|
|
64
|
+
session.value = { user: { username: updated.username, verified: updated.emailStatus === 'verified' } }
|
|
64
65
|
notice.value = 'Username updated.'
|
|
65
66
|
},
|
|
66
67
|
onError: onFormError,
|
|
@@ -141,7 +142,7 @@ export const useAccount = (
|
|
|
141
142
|
...(values.code ? { code: values.code } : {}),
|
|
142
143
|
},
|
|
143
144
|
})
|
|
144
|
-
|
|
145
|
+
session.value = null
|
|
145
146
|
await navigateTo('/login')
|
|
146
147
|
},
|
|
147
148
|
onError: onFormError,
|
|
@@ -150,14 +151,14 @@ export const useAccount = (
|
|
|
150
151
|
const signOut = () =>
|
|
151
152
|
runAction(async () => {
|
|
152
153
|
await $fetch('/api/auth/logout', { method: 'POST' })
|
|
153
|
-
|
|
154
|
+
session.value = null
|
|
154
155
|
await navigateTo('/login')
|
|
155
156
|
})
|
|
156
157
|
|
|
157
158
|
const signOutEverywhere = () =>
|
|
158
159
|
runAction(async () => {
|
|
159
160
|
await $fetch('/api/auth/logout-everywhere', { method: 'POST' })
|
|
160
|
-
|
|
161
|
+
session.value = null
|
|
161
162
|
await navigateTo('/login')
|
|
162
163
|
})
|
|
163
164
|
|
|
@@ -187,6 +188,7 @@ export const useAccount = (
|
|
|
187
188
|
actionBusy,
|
|
188
189
|
notice,
|
|
189
190
|
errorMessage,
|
|
191
|
+
refreshMe,
|
|
190
192
|
refreshSessions,
|
|
191
193
|
signOut,
|
|
192
194
|
signOutEverywhere,
|
|
@@ -35,7 +35,11 @@ export const useAuthLogin = (
|
|
|
35
35
|
} = {},
|
|
36
36
|
) => {
|
|
37
37
|
const route = useRoute()
|
|
38
|
-
const {
|
|
38
|
+
const { session } = useUserSession()
|
|
39
|
+
|
|
40
|
+
const applySession = (user: { readonly username: string; readonly emailStatus: string }) => {
|
|
41
|
+
session.value = { user: { username: user.username, verified: user.emailStatus === 'verified' } }
|
|
42
|
+
}
|
|
39
43
|
|
|
40
44
|
const step = ref<LoginStep>(route.query.totp === '1' ? { kind: 'totp' } : { kind: 'credentials' })
|
|
41
45
|
const turnstileToken = ref('')
|
|
@@ -71,7 +75,7 @@ export const useAuthLogin = (
|
|
|
71
75
|
step.value = { kind: 'totp', challenge: result.challenge }
|
|
72
76
|
return
|
|
73
77
|
}
|
|
74
|
-
|
|
78
|
+
applySession(result.user)
|
|
75
79
|
await navigateTo(destination())
|
|
76
80
|
},
|
|
77
81
|
onError: (error) => {
|
|
@@ -88,11 +92,11 @@ export const useAuthLogin = (
|
|
|
88
92
|
onSubmit: async (values) => {
|
|
89
93
|
if (step.value.kind !== 'totp') return
|
|
90
94
|
errorMessage.value = ''
|
|
91
|
-
await $fetch('/api/auth/login/totp', {
|
|
95
|
+
const user = await $fetch('/api/auth/login/totp', {
|
|
92
96
|
method: 'POST',
|
|
93
97
|
body: step.value.challenge ? { challenge: step.value.challenge, code: values.code } : { code: values.code },
|
|
94
98
|
})
|
|
95
|
-
|
|
99
|
+
applySession(user)
|
|
96
100
|
await navigateTo(destination())
|
|
97
101
|
},
|
|
98
102
|
onError: (error) => {
|
|
@@ -118,7 +122,7 @@ export const useAuthLogin = (
|
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
export const useAuthRegister = (options: { readonly formRef?: FormElementRef; readonly onResetCaptcha?: () => void } = {}) => {
|
|
121
|
-
const {
|
|
125
|
+
const { session } = useUserSession()
|
|
122
126
|
const turnstileToken = ref('')
|
|
123
127
|
const errorMessage = ref('')
|
|
124
128
|
|
|
@@ -129,12 +133,12 @@ export const useAuthRegister = (options: { readonly formRef?: FormElementRef; re
|
|
|
129
133
|
mapError: mapFields,
|
|
130
134
|
onSubmit: async (values) => {
|
|
131
135
|
errorMessage.value = ''
|
|
132
|
-
await $fetch('/api/auth/register', {
|
|
136
|
+
const user = await $fetch('/api/auth/register', {
|
|
133
137
|
method: 'POST',
|
|
134
138
|
body: { username: values.username, email: values.email, password: values.password },
|
|
135
139
|
headers: turnstileHeaders(turnstileToken.value),
|
|
136
140
|
})
|
|
137
|
-
|
|
141
|
+
session.value = { user: { username: user.username, verified: user.emailStatus === 'verified' } }
|
|
138
142
|
await navigateTo('/account')
|
|
139
143
|
},
|
|
140
144
|
onError: (error) => {
|
|
@@ -19,6 +19,7 @@ const {
|
|
|
19
19
|
actionBusy,
|
|
20
20
|
notice,
|
|
21
21
|
errorMessage,
|
|
22
|
+
refreshMe,
|
|
22
23
|
refreshSessions,
|
|
23
24
|
signOut,
|
|
24
25
|
signOutEverywhere,
|
|
@@ -131,7 +132,7 @@ await ready
|
|
|
131
132
|
</form>
|
|
132
133
|
</section>
|
|
133
134
|
|
|
134
|
-
<TotpSetup v-if="features.totp" />
|
|
135
|
+
<TotpSetup v-if="features.totp" :status="me.totpStatus" :recovery-codes-left="me.totpRecoveryCodesLeft" @updated="refreshMe()" />
|
|
135
136
|
|
|
136
137
|
<section>
|
|
137
138
|
<h2>Active sessions</h2>
|
|
@@ -37,11 +37,11 @@ export default defineNuxtConfig({
|
|
|
37
37
|
typescriptPlugin: true,
|
|
38
38
|
strictRouteTypes: true,
|
|
39
39
|
typedPages: true,
|
|
40
|
-
|
|
41
|
-
parallelBuild: false,
|
|
40
|
+
parallelBuild: true,
|
|
42
41
|
},
|
|
43
42
|
|
|
44
43
|
routeRules: {
|
|
44
|
+
'/': { swr: 60 },
|
|
45
45
|
'/api/**': { headers: { 'cache-control': 'no-store', 'content-security-policy': "default-src 'none'; frame-ancestors 'none'" } },
|
|
46
46
|
'/auth/**': { headers: { 'cache-control': 'no-store' } },
|
|
47
47
|
'/account': { headers: { 'x-robots-tag': 'noindex', 'cache-control': 'no-store' } },
|
|
@@ -54,6 +54,8 @@ export default defineNuxtConfig({
|
|
|
54
54
|
|
|
55
55
|
nitro: {
|
|
56
56
|
preset: 'cloudflare_module',
|
|
57
|
+
minify: true,
|
|
58
|
+
sourcemap: false,
|
|
57
59
|
experimental: { database: true, tasks: true, envExpansion: true },
|
|
58
60
|
scheduledTasks: {
|
|
59
61
|
'0 3 * * *': ['cleanup'],
|
|
@@ -96,6 +98,7 @@ export default defineNuxtConfig({
|
|
|
96
98
|
turnstileSecret: secret('Cloudflare Turnstile secret key.'),
|
|
97
99
|
turnstileRequired: flag(false, 'Fail closed when Turnstile secret is unset instead of skipping verification.'),
|
|
98
100
|
rateLimitScale: int(1, 'Multiplies strict Durable Object rate limits; raise only for local work or load tests.'),
|
|
101
|
+
d1Sessions: flag(false, 'Use Cloudflare D1 Sessions API (withSession) for global read replication with per-client bookmark cookies.'),
|
|
99
102
|
adminEmails: text('', 'Comma-separated allowlist of Cloudflare Access emails permitted to reach /admin.'),
|
|
100
103
|
oauth: {
|
|
101
104
|
google: { clientId: '', clientSecret: '' },
|
|
@@ -9,14 +9,15 @@
|
|
|
9
9
|
"preview": "nuxt preview",
|
|
10
10
|
"postinstall": "wrangler types && nuxt prepare",
|
|
11
11
|
"prepare": "effect-tsgo patch --no-typescript --oxlint && simple-git-hooks",
|
|
12
|
-
"typecheck": "wrangler types &&
|
|
12
|
+
"typecheck": "wrangler types && bun run typecheck:tsc",
|
|
13
|
+
"typecheck:tsc": "vue-tsc --build",
|
|
13
14
|
"lint": "oxlint --deny-warnings",
|
|
14
15
|
"lint:fix": "oxlint --fix",
|
|
15
16
|
"fmt": "oxfmt",
|
|
16
17
|
"fmt:check": "oxfmt --check",
|
|
17
18
|
"test": "vitest run",
|
|
18
19
|
"test:affected": "vitest run --since-last-run",
|
|
19
|
-
"check": "
|
|
20
|
+
"check": "wrangler types && bun run --parallel typecheck:tsc lint fmt:check test",
|
|
20
21
|
"db:migrate": "bun scripts/migrate.ts",
|
|
21
22
|
"db:migrate:remote": "bun scripts/migrate.ts --remote",
|
|
22
23
|
"deploy": "nuxt build && wrangler deploy"
|
|
@@ -25,27 +26,27 @@
|
|
|
25
26
|
"@humanonlyweb/cf-access": "0.1.2",
|
|
26
27
|
"@humanonlyweb/ui": "^0.7.1",
|
|
27
28
|
"db0": "^0.4.2",
|
|
28
|
-
"effect": "^4.
|
|
29
|
+
"effect": "^4.2.0",
|
|
29
30
|
"nuxt": "npm:nuxt-nightly@5x",
|
|
30
31
|
"nuxt-auth-utils": "0.6.2",
|
|
31
32
|
"qrcode": "^1.5.4",
|
|
32
|
-
"vue": "^3.5.
|
|
33
|
-
"vue-router": "^5.
|
|
33
|
+
"vue": "^3.5.47",
|
|
34
|
+
"vue-router": "^5.6.1"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@adonisjs/hash": "9.1.1",
|
|
37
|
-
"@effect/tsgo": "^0.74.
|
|
38
|
+
"@effect/tsgo": "^0.74.4",
|
|
38
39
|
"@types/node": "^26.6.11",
|
|
39
40
|
"@types/qrcode": "^1.5.6",
|
|
40
41
|
"miniflare": "5.20261113.0-beta",
|
|
41
|
-
"oxfmt": "^0.
|
|
42
|
+
"oxfmt": "^0.81.0",
|
|
42
43
|
"oxlint": "1.94.0",
|
|
43
44
|
"oxlint-tsgolint": "7.0.2009",
|
|
44
45
|
"simple-git-hooks": "2.14.0",
|
|
45
46
|
"typescript": "npm:typescript-native-bridge@6.0.3-bridge.18.tsgo.7.0.2",
|
|
46
47
|
"vitest": "^5.1.2",
|
|
47
48
|
"vue-tsc": "^3.3.14",
|
|
48
|
-
"wrangler": "^4.
|
|
49
|
+
"wrangler": "^4.171.0"
|
|
49
50
|
},
|
|
50
51
|
"overrides": {
|
|
51
52
|
"@nuxt/kit": "npm:@nuxt/kit-nightly@5.0.0-2611241632-f471666",
|
|
@@ -11,7 +11,7 @@ export default handleAuthed(
|
|
|
11
11
|
Effect.gen(function* () {
|
|
12
12
|
const actor = yield* UserActor
|
|
13
13
|
yield* Identity.use((identity) => identity.deleteAccount(actor.id, body))
|
|
14
|
-
yield* endUserSession(event)
|
|
14
|
+
yield* endUserSession(event, { alreadyRevoked: true })
|
|
15
15
|
}),
|
|
16
16
|
{ verification: 'allow-unverified' },
|
|
17
17
|
)
|
|
@@ -10,7 +10,7 @@ export default handleAuthed(
|
|
|
10
10
|
Effect.gen(function* () {
|
|
11
11
|
const actor = yield* UserActor
|
|
12
12
|
yield* Sessions.use((sessions) => sessions.endAll(actor.id))
|
|
13
|
-
yield* endUserSession(event)
|
|
13
|
+
yield* endUserSession(event, { alreadyRevoked: true })
|
|
14
14
|
}),
|
|
15
15
|
{ verification: 'allow-unverified' },
|
|
16
16
|
)
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import { Effect } from 'effect'
|
|
2
|
-
|
|
3
|
-
import { Sessions } from '#server/app/identity/sessions'
|
|
4
1
|
import { handlePublic } from '#server/core/http/handle'
|
|
5
|
-
import { endUserSession
|
|
2
|
+
import { endUserSession } from '#server/core/http/session'
|
|
6
3
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const sessionId = requestSessionId(event)
|
|
10
|
-
if (sessionId) yield* Sessions.use((sessions) => sessions.end(sessionId))
|
|
11
|
-
yield* endUserSession(event)
|
|
12
|
-
}),
|
|
13
|
-
)
|
|
4
|
+
/** `clearUserSession` invokes `sessionHooks.clear`, which deletes the D1 session row and clears the cookie in one pass. */
|
|
5
|
+
export default handlePublic({}, (_input, event) => endUserSession(event))
|
|
@@ -3,7 +3,7 @@ import { Effect } from 'effect'
|
|
|
3
3
|
import { Identity } from '#server/app/identity/service'
|
|
4
4
|
import { EmailVerification } from '#server/app/identity/verification'
|
|
5
5
|
import { handlePublic } from '#server/core/http/handle'
|
|
6
|
-
import { establishUserSession } from '#server/core/http/session'
|
|
6
|
+
import { establishUserSession, waitUntilOf } from '#server/core/http/session'
|
|
7
7
|
import { AuthUserView, RegisterBody } from '#shared/utils/auth'
|
|
8
8
|
|
|
9
9
|
export default handlePublic({ body: RegisterBody, response: AuthUserView, limit: 'register', captcha: true }, ({ body }, event) =>
|
|
@@ -11,8 +11,16 @@ export default handlePublic({ body: RegisterBody, response: AuthUserView, limit:
|
|
|
11
11
|
const identity = yield* Identity
|
|
12
12
|
const verification = yield* EmailVerification
|
|
13
13
|
const user = yield* identity.register(body)
|
|
14
|
-
|
|
15
|
-
yield*
|
|
14
|
+
const waitUntil = waitUntilOf(event)
|
|
15
|
+
yield* Effect.all(
|
|
16
|
+
[
|
|
17
|
+
establishUserSession(event, user),
|
|
18
|
+
verification
|
|
19
|
+
.send(user.id, waitUntil ? { user, waitUntil } : { user })
|
|
20
|
+
.pipe(Effect.catch((error) => Effect.logWarning(`Initial verification send skipped (${error._tag}): ${error.message}`))),
|
|
21
|
+
],
|
|
22
|
+
{ concurrency: 'unbounded' },
|
|
23
|
+
)
|
|
16
24
|
return user
|
|
17
25
|
}),
|
|
18
26
|
)
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { EmailVerification } from '#server/app/identity/verification'
|
|
2
2
|
import { handleAuthed } from '#server/core/http/handle'
|
|
3
|
-
import { UserActor } from '#server/core/http/session'
|
|
3
|
+
import { UserActor, waitUntilOf } from '#server/core/http/session'
|
|
4
4
|
|
|
5
|
-
export default handleAuthed(
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export default handleAuthed(
|
|
6
|
+
{},
|
|
7
|
+
(_input, event) => {
|
|
8
|
+
const waitUntil = waitUntilOf(event)
|
|
9
|
+
return UserActor.use((actor) => EmailVerification.use((verification) => verification.send(actor.id, waitUntil ? { waitUntil } : undefined)))
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
verification: 'allow-unverified',
|
|
13
|
+
},
|
|
14
|
+
)
|
|
@@ -25,6 +25,15 @@ const decodeLockoutState = (row: typeof FailureRow.Type): LockoutState => {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
export const assertFailureRowUnlocked = (row: typeof FailureRow.Type) =>
|
|
29
|
+
Effect.gen(function* () {
|
|
30
|
+
const state = decodeLockoutState(row)
|
|
31
|
+
const now = DateTime.formatIso(yield* DateTime.now)
|
|
32
|
+
if (state._tag === 'Locked' && state.lockedUntil > now) {
|
|
33
|
+
return yield* new RateLimited({ message: `Too many wrong attempts. Try again in ${LOCK_MINUTES} minutes, or reset your password.` })
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
28
37
|
/**
|
|
29
38
|
* Shared per-subject sign-in and 2FA attempt lockout backed by `login_failures`.
|
|
30
39
|
* Explicit state machine: absent -> counting(1..MAX-1) -> locked(locked_until) -> absent.
|
|
@@ -46,11 +55,7 @@ export class LoginLockout extends Context.Service<
|
|
|
46
55
|
Effect.gen(function* () {
|
|
47
56
|
const row = yield* db.first(FailureRow, `SELECT status, failures, locked_until FROM login_failures WHERE subject = ?`, [subject]).pipe(Effect.orDie)
|
|
48
57
|
if (!row) return
|
|
49
|
-
|
|
50
|
-
const now = DateTime.formatIso(yield* DateTime.now)
|
|
51
|
-
if (state._tag === 'Locked' && state.lockedUntil > now) {
|
|
52
|
-
return yield* new RateLimited({ message: `Too many wrong attempts. Try again in ${LOCK_MINUTES} minutes, or reset your password.` })
|
|
53
|
-
}
|
|
58
|
+
yield* assertFailureRowUnlocked(row)
|
|
54
59
|
})
|
|
55
60
|
|
|
56
61
|
const recordFailure = (subject: string) =>
|