@humanonlyweb/create-nuxtflare 0.2.0 → 0.2.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/dist/cli.js +17 -17
- package/dist/template/CLAUDE.md +1 -0
- package/dist/template/app/composables/use-account.ts +178 -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 +77 -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/server/app/identity/service.ts +34 -30
- package/dist/template/server/app/identity/sessions.ts +19 -28
- package/dist/template/server/app/identity/totp.ts +12 -4
- package/dist/template/server/core/db/atomic.ts +9 -11
- package/dist/template/server/core/http/handle.ts +4 -9
- package/dist/template/server/core/platform/seal.ts +13 -16
- package/dist/template/shared/utils/schema-validation.ts +24 -3
- package/package.json +17 -17
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
definePageMeta({ middleware: 'auth' })
|
|
3
3
|
|
|
4
|
+
const profileFormRef = useTemplateRef<HTMLFormElement>('profile-form')
|
|
5
|
+
const passwordFormRef = useTemplateRef<HTMLFormElement>('password-form')
|
|
6
|
+
const emailFormRef = useTemplateRef<HTMLFormElement>('email-form')
|
|
7
|
+
const deleteFormRef = useTemplateRef<HTMLFormElement>('delete-form')
|
|
8
|
+
|
|
4
9
|
const {
|
|
5
10
|
me,
|
|
6
11
|
features,
|
|
7
12
|
canUseVerifiedActions,
|
|
8
13
|
sessionList,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
newPassword,
|
|
15
|
-
passwordCode,
|
|
16
|
-
deleteConfirm,
|
|
17
|
-
deletePassword,
|
|
18
|
-
deleteCode,
|
|
19
|
-
busy,
|
|
14
|
+
profile,
|
|
15
|
+
passwordForm,
|
|
16
|
+
emailForm,
|
|
17
|
+
deleteForm,
|
|
18
|
+
actionBusy,
|
|
20
19
|
notice,
|
|
21
20
|
errorMessage,
|
|
22
21
|
refreshSessions,
|
|
23
22
|
signOut,
|
|
24
23
|
signOutEverywhere,
|
|
25
24
|
resendVerification,
|
|
26
|
-
saveProfile,
|
|
27
|
-
savePassword,
|
|
28
|
-
requestEmailChange,
|
|
29
25
|
cancelEmailChange,
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
} = await useAccount({ profileFormRef, passwordFormRef, emailFormRef, deleteFormRef })
|
|
27
|
+
|
|
28
|
+
const { form: profileValues, errors: profileErrors, processing: profileProcessing, submit: saveProfile } = profile
|
|
29
|
+
const { form: passwordValues, errors: passwordErrors, processing: passwordProcessing, submit: savePassword } = passwordForm
|
|
30
|
+
const { form: emailValues, errors: emailErrors, processing: emailProcessing, submit: requestEmailChange } = emailForm
|
|
31
|
+
const { form: deleteValues, errors: deleteErrors, processing: deleteProcessing, submit: deleteAccount } = deleteForm
|
|
32
32
|
</script>
|
|
33
33
|
|
|
34
34
|
<template>
|
|
@@ -38,42 +38,60 @@ const {
|
|
|
38
38
|
<p v-if="notice" role="status">{{ notice }}</p>
|
|
39
39
|
|
|
40
40
|
<p>{{ me.username }} ({{ me.email }}) — email {{ me.emailStatus }}</p>
|
|
41
|
-
<button type="button" :disabled="
|
|
41
|
+
<button type="button" :disabled="actionBusy" @click="signOut">Sign out</button>
|
|
42
42
|
|
|
43
43
|
<section v-if="me.emailStatus === 'unverified'">
|
|
44
44
|
<h2>Confirm your email</h2>
|
|
45
45
|
<p>Check your inbox for a confirmation link, or request a fresh one.</p>
|
|
46
|
-
<button type="button" :disabled="
|
|
46
|
+
<button type="button" :disabled="actionBusy" @click="resendVerification">Resend verification email</button>
|
|
47
47
|
</section>
|
|
48
48
|
|
|
49
49
|
<template v-if="canUseVerifiedActions">
|
|
50
50
|
<section>
|
|
51
51
|
<h2>Profile</h2>
|
|
52
|
-
<form @submit
|
|
52
|
+
<form ref="profile-form" novalidate @submit="saveProfile">
|
|
53
53
|
<label>
|
|
54
54
|
Username
|
|
55
|
-
<input v-model="username" autocomplete="username" required />
|
|
55
|
+
<input v-model="profileValues.username" name="username" autocomplete="username" :aria-invalid="Boolean(profileErrors.username)" required />
|
|
56
|
+
<span v-if="profileErrors.username" role="alert">{{ profileErrors.username }}</span>
|
|
56
57
|
</label>
|
|
57
|
-
<button type="submit" :disabled="
|
|
58
|
+
<button type="submit" :disabled="profileProcessing">Save username</button>
|
|
58
59
|
</form>
|
|
59
60
|
</section>
|
|
60
61
|
|
|
61
62
|
<section>
|
|
62
63
|
<h2>{{ me.hasPassword ? 'Change password' : 'Set password' }}</h2>
|
|
63
|
-
<form @submit
|
|
64
|
+
<form ref="password-form" novalidate @submit="savePassword">
|
|
64
65
|
<label v-if="me.hasPassword">
|
|
65
66
|
Current password
|
|
66
|
-
<input
|
|
67
|
+
<input
|
|
68
|
+
v-model="passwordValues.currentPassword"
|
|
69
|
+
name="currentPassword"
|
|
70
|
+
type="password"
|
|
71
|
+
autocomplete="current-password"
|
|
72
|
+
:aria-invalid="Boolean(passwordErrors.currentPassword)"
|
|
73
|
+
required
|
|
74
|
+
/>
|
|
75
|
+
<span v-if="passwordErrors.currentPassword" role="alert">{{ passwordErrors.currentPassword }}</span>
|
|
67
76
|
</label>
|
|
68
77
|
<label>
|
|
69
78
|
New password
|
|
70
|
-
<input
|
|
79
|
+
<input
|
|
80
|
+
v-model="passwordValues.newPassword"
|
|
81
|
+
name="newPassword"
|
|
82
|
+
type="password"
|
|
83
|
+
autocomplete="new-password"
|
|
84
|
+
:aria-invalid="Boolean(passwordErrors.newPassword)"
|
|
85
|
+
required
|
|
86
|
+
/>
|
|
87
|
+
<span v-if="passwordErrors.newPassword" role="alert">{{ passwordErrors.newPassword }}</span>
|
|
71
88
|
</label>
|
|
72
89
|
<label v-if="me.hasPassword && features.totp && me.totpStatus === 'enabled'">
|
|
73
90
|
Authenticator or recovery code
|
|
74
|
-
<input v-model="
|
|
91
|
+
<input v-model="passwordValues.code" name="code" autocomplete="one-time-code" :aria-invalid="Boolean(passwordErrors.code)" required />
|
|
92
|
+
<span v-if="passwordErrors.code" role="alert">{{ passwordErrors.code }}</span>
|
|
75
93
|
</label>
|
|
76
|
-
<button type="submit" :disabled="
|
|
94
|
+
<button type="submit" :disabled="passwordProcessing">{{ me.hasPassword ? 'Change password' : 'Set password' }}</button>
|
|
77
95
|
</form>
|
|
78
96
|
</section>
|
|
79
97
|
|
|
@@ -81,22 +99,32 @@ const {
|
|
|
81
99
|
<h2>Email address</h2>
|
|
82
100
|
<div v-if="me.pendingEmailChange">
|
|
83
101
|
<p>Pending change to {{ me.pendingEmailChange.email }}.</p>
|
|
84
|
-
<button type="button" :disabled="
|
|
102
|
+
<button type="button" :disabled="actionBusy" @click="cancelEmailChange">Cancel pending change</button>
|
|
85
103
|
</div>
|
|
86
|
-
<form v-else @submit
|
|
104
|
+
<form v-else ref="email-form" novalidate @submit="requestEmailChange">
|
|
87
105
|
<label>
|
|
88
106
|
New email
|
|
89
|
-
<input v-model="
|
|
107
|
+
<input v-model="emailValues.email" name="email" type="email" autocomplete="email" :aria-invalid="Boolean(emailErrors.email)" required />
|
|
108
|
+
<span v-if="emailErrors.email" role="alert">{{ emailErrors.email }}</span>
|
|
90
109
|
</label>
|
|
91
110
|
<label>
|
|
92
111
|
Current password
|
|
93
|
-
<input
|
|
112
|
+
<input
|
|
113
|
+
v-model="emailValues.password"
|
|
114
|
+
name="password"
|
|
115
|
+
type="password"
|
|
116
|
+
autocomplete="current-password"
|
|
117
|
+
:aria-invalid="Boolean(emailErrors.password)"
|
|
118
|
+
required
|
|
119
|
+
/>
|
|
120
|
+
<span v-if="emailErrors.password" role="alert">{{ emailErrors.password }}</span>
|
|
94
121
|
</label>
|
|
95
122
|
<label v-if="features.totp && me.totpStatus === 'enabled'">
|
|
96
123
|
Authenticator or recovery code
|
|
97
|
-
<input v-model="
|
|
124
|
+
<input v-model="emailValues.code" name="code" autocomplete="one-time-code" :aria-invalid="Boolean(emailErrors.code)" required />
|
|
125
|
+
<span v-if="emailErrors.code" role="alert">{{ emailErrors.code }}</span>
|
|
98
126
|
</label>
|
|
99
|
-
<button type="submit" :disabled="
|
|
127
|
+
<button type="submit" :disabled="emailProcessing">Change email</button>
|
|
100
128
|
</form>
|
|
101
129
|
</section>
|
|
102
130
|
|
|
@@ -109,27 +137,37 @@ const {
|
|
|
109
137
|
{{ item.device }} — last seen {{ item.lastSeenAt }}<span v-if="item.current"> (current)</span>
|
|
110
138
|
</li>
|
|
111
139
|
</ul>
|
|
112
|
-
<button type="button" :disabled="
|
|
113
|
-
<button type="button" :disabled="
|
|
140
|
+
<button type="button" :disabled="actionBusy" @click="refreshSessions()">Refresh sessions</button>
|
|
141
|
+
<button type="button" :disabled="actionBusy" @click="signOutEverywhere">Sign out everywhere</button>
|
|
114
142
|
</section>
|
|
115
143
|
</template>
|
|
116
144
|
|
|
117
145
|
<section>
|
|
118
146
|
<h2>Delete account</h2>
|
|
119
|
-
<form @submit
|
|
147
|
+
<form ref="delete-form" novalidate @submit="deleteAccount">
|
|
120
148
|
<label>
|
|
121
149
|
Type {{ me.username }} to confirm
|
|
122
|
-
<input v-model="
|
|
150
|
+
<input v-model="deleteValues.confirm" name="confirm" :aria-invalid="Boolean(deleteErrors.confirm)" required />
|
|
151
|
+
<span v-if="deleteErrors.confirm" role="alert">{{ deleteErrors.confirm }}</span>
|
|
123
152
|
</label>
|
|
124
153
|
<label v-if="me.hasPassword">
|
|
125
154
|
Current password
|
|
126
|
-
<input
|
|
155
|
+
<input
|
|
156
|
+
v-model="deleteValues.password"
|
|
157
|
+
name="password"
|
|
158
|
+
type="password"
|
|
159
|
+
autocomplete="current-password"
|
|
160
|
+
:aria-invalid="Boolean(deleteErrors.password)"
|
|
161
|
+
required
|
|
162
|
+
/>
|
|
163
|
+
<span v-if="deleteErrors.password" role="alert">{{ deleteErrors.password }}</span>
|
|
127
164
|
</label>
|
|
128
165
|
<label v-if="features.totp && me.totpStatus === 'enabled'">
|
|
129
166
|
Authenticator or recovery code
|
|
130
|
-
<input v-model="
|
|
167
|
+
<input v-model="deleteValues.code" name="code" autocomplete="one-time-code" :aria-invalid="Boolean(deleteErrors.code)" required />
|
|
168
|
+
<span v-if="deleteErrors.code" role="alert">{{ deleteErrors.code }}</span>
|
|
131
169
|
</label>
|
|
132
|
-
<button type="submit" :disabled="
|
|
170
|
+
<button type="submit" :disabled="deleteProcessing">Delete account</button>
|
|
133
171
|
</form>
|
|
134
172
|
</section>
|
|
135
173
|
</main>
|
|
@@ -1,39 +1,24 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const email = ref('')
|
|
5
|
-
const password = ref('')
|
|
6
|
-
const busy = ref(false)
|
|
7
|
-
const errorMessage = ref('')
|
|
8
|
-
|
|
9
|
-
const submit = async () => {
|
|
10
|
-
errorMessage.value = ''
|
|
11
|
-
busy.value = true
|
|
12
|
-
try {
|
|
13
|
-
await $fetch('/api/admin/session', { method: 'POST', body: { email: email.value, password: password.value } })
|
|
14
|
-
await navigateTo('/admin')
|
|
15
|
-
} catch (error) {
|
|
16
|
-
errorMessage.value = problemOf(error).message
|
|
17
|
-
} finally {
|
|
18
|
-
busy.value = false
|
|
19
|
-
}
|
|
20
|
-
}
|
|
2
|
+
const formRef = useTemplateRef<HTMLFormElement>('admin-login-form')
|
|
3
|
+
const { form, errors, processing, submit, errorMessage } = useAdminLogin({ formRef })
|
|
21
4
|
</script>
|
|
22
5
|
|
|
23
6
|
<template>
|
|
24
7
|
<main>
|
|
25
8
|
<h1>Admin sign in</h1>
|
|
26
9
|
<p v-if="errorMessage" role="alert">{{ errorMessage }}</p>
|
|
27
|
-
<form @submit
|
|
10
|
+
<form ref="admin-login-form" novalidate @submit="submit">
|
|
28
11
|
<label>
|
|
29
12
|
Email
|
|
30
|
-
<input v-model="email" type="email" autocomplete="username" required />
|
|
13
|
+
<input v-model="form.email" name="email" type="email" autocomplete="username" :aria-invalid="Boolean(errors.email)" required />
|
|
14
|
+
<span v-if="errors.email" role="alert">{{ errors.email }}</span>
|
|
31
15
|
</label>
|
|
32
16
|
<label>
|
|
33
17
|
Password
|
|
34
|
-
<input v-model="password" type="password" autocomplete="current-password" required />
|
|
18
|
+
<input v-model="form.password" name="password" type="password" autocomplete="current-password" :aria-invalid="Boolean(errors.password)" required />
|
|
19
|
+
<span v-if="errors.password" role="alert">{{ errors.password }}</span>
|
|
35
20
|
</label>
|
|
36
|
-
<button type="submit" :disabled="
|
|
21
|
+
<button type="submit" :disabled="processing">Sign in</button>
|
|
37
22
|
</form>
|
|
38
23
|
</main>
|
|
39
24
|
</template>
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
definePageMeta({ middleware: 'guest' })
|
|
3
3
|
|
|
4
|
+
const formRef = useTemplateRef<HTMLFormElement>('forgot-form')
|
|
4
5
|
const turnstile = ref<{ reset: () => void } | null>(null)
|
|
5
|
-
const {
|
|
6
|
+
const { form, errors, processing, submit, step, turnstileToken, errorMessage } = useForgotPassword({
|
|
7
|
+
formRef,
|
|
8
|
+
onResetCaptcha: () => turnstile.value?.reset(),
|
|
9
|
+
})
|
|
6
10
|
</script>
|
|
7
11
|
|
|
8
12
|
<template>
|
|
@@ -15,13 +19,14 @@ const { step, email, turnstileToken, busy, errorMessage, submit } = useForgotPas
|
|
|
15
19
|
<p><NuxtLink to="/login">Back to sign in</NuxtLink></p>
|
|
16
20
|
</template>
|
|
17
21
|
|
|
18
|
-
<form v-else @submit
|
|
22
|
+
<form v-else ref="forgot-form" novalidate @submit="submit">
|
|
19
23
|
<label>
|
|
20
24
|
Email
|
|
21
|
-
<input v-model="email" type="email" autocomplete="email" required />
|
|
25
|
+
<input v-model="form.email" name="email" type="email" autocomplete="email" :aria-invalid="Boolean(errors.email)" required />
|
|
26
|
+
<span v-if="errors.email" role="alert">{{ errors.email }}</span>
|
|
22
27
|
</label>
|
|
23
28
|
<TurnstileWidget ref="turnstile" v-model="turnstileToken" />
|
|
24
|
-
<button type="submit" :disabled="
|
|
29
|
+
<button type="submit" :disabled="processing">Send reset link</button>
|
|
25
30
|
<p><NuxtLink to="/login">Back to sign in</NuxtLink></p>
|
|
26
31
|
</form>
|
|
27
32
|
</main>
|
|
@@ -2,9 +2,18 @@
|
|
|
2
2
|
definePageMeta({ middleware: 'guest' })
|
|
3
3
|
|
|
4
4
|
const features = useFeatures()
|
|
5
|
+
const credentialsFormRef = useTemplateRef<HTMLFormElement>('credentials-form')
|
|
6
|
+
const totpFormRef = useTemplateRef<HTMLFormElement>('totp-form')
|
|
5
7
|
const turnstile = ref<{ reset: () => void } | null>(null)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
const { step, credentials, totp, turnstileToken, errorMessage, rememberOAuthNext, backToCredentials } = useAuthLogin({
|
|
10
|
+
credentialsFormRef,
|
|
11
|
+
totpFormRef,
|
|
12
|
+
onResetCaptcha: () => turnstile.value?.reset(),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const { form: credForm, errors: credErrors, processing: credProcessing, submit: submitCredentials } = credentials
|
|
16
|
+
const { form: totpForm, errors: totpErrors, processing: totpProcessing, submit: submitTotp } = totp
|
|
8
17
|
</script>
|
|
9
18
|
|
|
10
19
|
<template>
|
|
@@ -12,28 +21,38 @@ const { step, identity, password, code, turnstileToken, busy, errorMessage, reme
|
|
|
12
21
|
<h1>Sign in</h1>
|
|
13
22
|
<p v-if="errorMessage" role="alert">{{ errorMessage }}</p>
|
|
14
23
|
|
|
15
|
-
<form v-if="step.kind === 'credentials'" @submit
|
|
24
|
+
<form v-if="step.kind === 'credentials'" ref="credentials-form" novalidate @submit="submitCredentials">
|
|
16
25
|
<label>
|
|
17
26
|
Email or username
|
|
18
|
-
<input v-model="identity" autocomplete="username" required />
|
|
27
|
+
<input v-model="credForm.identity" name="identity" autocomplete="username" :aria-invalid="Boolean(credErrors.identity)" required />
|
|
28
|
+
<span v-if="credErrors.identity" role="alert">{{ credErrors.identity }}</span>
|
|
19
29
|
</label>
|
|
20
30
|
<label>
|
|
21
31
|
Password
|
|
22
|
-
<input
|
|
32
|
+
<input
|
|
33
|
+
v-model="credForm.password"
|
|
34
|
+
name="password"
|
|
35
|
+
type="password"
|
|
36
|
+
autocomplete="current-password"
|
|
37
|
+
:aria-invalid="Boolean(credErrors.password)"
|
|
38
|
+
required
|
|
39
|
+
/>
|
|
40
|
+
<span v-if="credErrors.password" role="alert">{{ credErrors.password }}</span>
|
|
23
41
|
</label>
|
|
24
42
|
<TurnstileWidget ref="turnstile" v-model="turnstileToken" />
|
|
25
|
-
<button type="submit" :disabled="
|
|
43
|
+
<button type="submit" :disabled="credProcessing">Sign in</button>
|
|
26
44
|
<p><NuxtLink to="/forgot-password">Forgot your password?</NuxtLink></p>
|
|
27
45
|
</form>
|
|
28
46
|
|
|
29
|
-
<form v-else @submit
|
|
47
|
+
<form v-else ref="totp-form" novalidate @submit="submitTotp">
|
|
30
48
|
<p>Enter the 6-digit code from your authenticator app or a recovery code.</p>
|
|
31
49
|
<label>
|
|
32
50
|
Verification code
|
|
33
|
-
<input v-model="code" autocomplete="one-time-code" required />
|
|
51
|
+
<input v-model="totpForm.code" name="code" autocomplete="one-time-code" :aria-invalid="Boolean(totpErrors.code)" required />
|
|
52
|
+
<span v-if="totpErrors.code" role="alert">{{ totpErrors.code }}</span>
|
|
34
53
|
</label>
|
|
35
|
-
<button type="submit" :disabled="
|
|
36
|
-
<button type="button" :disabled="
|
|
54
|
+
<button type="submit" :disabled="totpProcessing">Verify</button>
|
|
55
|
+
<button type="button" :disabled="totpProcessing" @click="backToCredentials">Back</button>
|
|
37
56
|
</form>
|
|
38
57
|
|
|
39
58
|
<p v-if="features.googleOAuth && step.kind === 'credentials'">
|
|
@@ -1,29 +1,41 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
definePageMeta({ middleware: 'guest' })
|
|
3
3
|
|
|
4
|
+
const formRef = useTemplateRef<HTMLFormElement>('register-form')
|
|
4
5
|
const turnstile = ref<{ reset: () => void } | null>(null)
|
|
5
|
-
const {
|
|
6
|
+
const { form, errors, processing, submit, turnstileToken, errorMessage } = useAuthRegister({
|
|
7
|
+
formRef,
|
|
8
|
+
onResetCaptcha: () => turnstile.value?.reset(),
|
|
9
|
+
})
|
|
6
10
|
</script>
|
|
7
11
|
|
|
8
12
|
<template>
|
|
9
13
|
<main>
|
|
10
14
|
<h1>Create account</h1>
|
|
11
15
|
<p v-if="errorMessage" role="alert">{{ errorMessage }}</p>
|
|
12
|
-
<form @submit
|
|
16
|
+
<form ref="register-form" novalidate @submit="submit">
|
|
13
17
|
<label>
|
|
14
18
|
Username
|
|
15
|
-
<input v-model="username" autocomplete="username" required />
|
|
19
|
+
<input v-model="form.username" name="username" autocomplete="username" :aria-invalid="Boolean(errors.username)" required />
|
|
20
|
+
<span v-if="errors.username" role="alert">{{ errors.username }}</span>
|
|
16
21
|
</label>
|
|
17
22
|
<label>
|
|
18
23
|
Email
|
|
19
|
-
<input v-model="email" type="email" autocomplete="email" required />
|
|
24
|
+
<input v-model="form.email" name="email" type="email" autocomplete="email" :aria-invalid="Boolean(errors.email)" required />
|
|
25
|
+
<span v-if="errors.email" role="alert">{{ errors.email }}</span>
|
|
20
26
|
</label>
|
|
21
27
|
<label>
|
|
22
28
|
Password
|
|
23
|
-
<input v-model="password" type="password" autocomplete="new-password" required />
|
|
29
|
+
<input v-model="form.password" name="password" type="password" autocomplete="new-password" :aria-invalid="Boolean(errors.password)" required />
|
|
30
|
+
<span v-if="errors.password" role="alert">{{ errors.password }}</span>
|
|
31
|
+
</label>
|
|
32
|
+
<label>
|
|
33
|
+
Confirm password
|
|
34
|
+
<input v-model="form.confirm" name="confirm" type="password" autocomplete="new-password" :aria-invalid="Boolean(errors.confirm)" required />
|
|
35
|
+
<span v-if="errors.confirm" role="alert">{{ errors.confirm }}</span>
|
|
24
36
|
</label>
|
|
25
37
|
<TurnstileWidget ref="turnstile" v-model="turnstileToken" />
|
|
26
|
-
<button type="submit" :disabled="
|
|
38
|
+
<button type="submit" :disabled="processing">Create account</button>
|
|
27
39
|
</form>
|
|
28
40
|
</main>
|
|
29
41
|
</template>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
const
|
|
2
|
+
const formRef = useTemplateRef<HTMLFormElement>('reset-form')
|
|
3
|
+
const { form, errors, processing, submit, step, errorMessage } = usePasswordReset({ formRef })
|
|
3
4
|
</script>
|
|
4
5
|
|
|
5
6
|
<template>
|
|
@@ -16,16 +17,18 @@ const { step, password, confirm, busy, errorMessage, submit } = usePasswordReset
|
|
|
16
17
|
<p>Your password has been updated and existing sessions were signed out.</p>
|
|
17
18
|
<p><NuxtLink to="/login">Sign in</NuxtLink></p>
|
|
18
19
|
</template>
|
|
19
|
-
<form v-else @submit
|
|
20
|
+
<form v-else ref="reset-form" novalidate @submit="submit">
|
|
20
21
|
<label>
|
|
21
22
|
New password
|
|
22
|
-
<input v-model="password" type="password" autocomplete="new-password" required />
|
|
23
|
+
<input v-model="form.password" name="password" type="password" autocomplete="new-password" :aria-invalid="Boolean(errors.password)" required />
|
|
24
|
+
<span v-if="errors.password" role="alert">{{ errors.password }}</span>
|
|
23
25
|
</label>
|
|
24
26
|
<label>
|
|
25
27
|
Confirm password
|
|
26
|
-
<input v-model="confirm" type="password" autocomplete="new-password" required />
|
|
28
|
+
<input v-model="form.confirm" name="confirm" type="password" autocomplete="new-password" :aria-invalid="Boolean(errors.confirm)" required />
|
|
29
|
+
<span v-if="errors.confirm" role="alert">{{ errors.confirm }}</span>
|
|
27
30
|
</label>
|
|
28
|
-
<button type="submit" :disabled="
|
|
31
|
+
<button type="submit" :disabled="processing">Update password</button>
|
|
29
32
|
</form>
|
|
30
33
|
</main>
|
|
31
34
|
</template>
|
|
@@ -15,8 +15,13 @@ const features = {
|
|
|
15
15
|
|
|
16
16
|
export default defineNuxtConfig({
|
|
17
17
|
devtools: { enabled: true },
|
|
18
|
-
modules: ['nuxt-auth-utils', '@humanonlyweb/cf-access/nuxt'],
|
|
18
|
+
modules: ['nuxt-auth-utils', '@humanonlyweb/cf-access/nuxt', '@humanonlyweb/ui/nuxt'],
|
|
19
19
|
|
|
20
|
+
ui: {
|
|
21
|
+
prefix: 'Ui',
|
|
22
|
+
css: true,
|
|
23
|
+
composables: true,
|
|
24
|
+
},
|
|
20
25
|
cfAccess: { protect: ['/admin/**', '/api/admin/**'] },
|
|
21
26
|
compatibilityDate: 'latest',
|
|
22
27
|
|
|
@@ -383,6 +383,30 @@ export class Identity extends Context.Service<
|
|
|
383
383
|
return toAuthUser(updated)
|
|
384
384
|
})
|
|
385
385
|
|
|
386
|
+
const requireReauth = (
|
|
387
|
+
user: typeof LoginUserRow.Type,
|
|
388
|
+
input: { readonly password?: string | undefined; readonly code?: string | undefined },
|
|
389
|
+
messages: { readonly password: string; readonly code: string },
|
|
390
|
+
) =>
|
|
391
|
+
Effect.gen(function* () {
|
|
392
|
+
if (user.password_hash) {
|
|
393
|
+
const subject = `user:${user.id}`
|
|
394
|
+
yield* lockout.assertUnlocked(subject)
|
|
395
|
+
if (!input.password || !(yield* hasher.verify(user.password_hash, input.password))) {
|
|
396
|
+
yield* lockout.recordFailure(subject)
|
|
397
|
+
return yield* new Unauthorized({ message: messages.password })
|
|
398
|
+
}
|
|
399
|
+
yield* lockout.clear(subject)
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const totpState = decodeTotpState(user)
|
|
403
|
+
if (config.features.totp && totpState._tag === 'Enabled') {
|
|
404
|
+
if (!input.code) return yield* new Unauthorized({ message: messages.code })
|
|
405
|
+
const ok = yield* totp.verifySecondFactor(user.id, input.code)
|
|
406
|
+
if (!ok) return yield* new Unauthorized({ message: WRONG_CODE })
|
|
407
|
+
}
|
|
408
|
+
})
|
|
409
|
+
|
|
386
410
|
const setPassword = Effect.fn('Identity.setPassword')(function* (
|
|
387
411
|
userId: string,
|
|
388
412
|
input: {
|
|
@@ -402,20 +426,11 @@ export class Identity extends Context.Service<
|
|
|
402
426
|
if (!user) return yield* new NotFound({ resource: 'User', id: userId })
|
|
403
427
|
|
|
404
428
|
if (user.password_hash) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}
|
|
411
|
-
yield* lockout.clear(subject)
|
|
412
|
-
|
|
413
|
-
const totpState = decodeTotpState(user)
|
|
414
|
-
if (config.features.totp && totpState._tag === 'Enabled') {
|
|
415
|
-
if (!input.code) return yield* new Unauthorized({ message: 'Enter your verification code to change your password.' })
|
|
416
|
-
const ok = yield* totp.verifySecondFactor(user.id, input.code)
|
|
417
|
-
if (!ok) return yield* new Unauthorized({ message: WRONG_CODE })
|
|
418
|
-
}
|
|
429
|
+
yield* requireReauth(
|
|
430
|
+
user,
|
|
431
|
+
{ password: input.currentPassword, code: input.code },
|
|
432
|
+
{ password: 'The current password is not right.', code: 'Enter your verification code to change your password.' },
|
|
433
|
+
)
|
|
419
434
|
|
|
420
435
|
const nextHash = yield* hasher.hash(input.newPassword)
|
|
421
436
|
yield* atomic
|
|
@@ -467,22 +482,11 @@ export class Identity extends Context.Service<
|
|
|
467
482
|
return yield* new Unprocessable({ message: `Type ${user.username} to confirm deletion.` })
|
|
468
483
|
}
|
|
469
484
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
return yield* new Unauthorized({ message: 'Enter your current password to delete your account.' })
|
|
476
|
-
}
|
|
477
|
-
yield* lockout.clear(subject)
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
const totpState = decodeTotpState(user)
|
|
481
|
-
if (config.features.totp && totpState._tag === 'Enabled') {
|
|
482
|
-
if (!input.code) return yield* new Unauthorized({ message: 'Enter your verification code to delete your account.' })
|
|
483
|
-
const ok = yield* totp.verifySecondFactor(user.id, input.code)
|
|
484
|
-
if (!ok) return yield* new Unauthorized({ message: WRONG_CODE })
|
|
485
|
-
}
|
|
485
|
+
yield* requireReauth(
|
|
486
|
+
user,
|
|
487
|
+
{ password: input.password, code: input.code },
|
|
488
|
+
{ password: 'Enter your current password to delete your account.', code: 'Enter your verification code to delete your account.' },
|
|
489
|
+
)
|
|
486
490
|
|
|
487
491
|
yield* sessions.forget(userId)
|
|
488
492
|
yield* db.run(`DELETE FROM users WHERE id = ?`, [userId]).pipe(Effect.orDie)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context, DateTime, Effect, Layer, Schema } from 'effect'
|
|
1
|
+
import { Cache, Context, DateTime, Effect, Layer, Schema } from 'effect'
|
|
2
2
|
|
|
3
3
|
import type { EmailStatus } from '#shared/utils/auth'
|
|
4
4
|
|
|
@@ -38,7 +38,7 @@ export interface SessionUser {
|
|
|
38
38
|
readonly emailStatus: EmailStatus
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const
|
|
41
|
+
const REMEMBER_TTL = '3 seconds'
|
|
42
42
|
const REMEMBER_MAX = 1000
|
|
43
43
|
|
|
44
44
|
export interface VerifySessionOptions {
|
|
@@ -62,24 +62,18 @@ export class Sessions extends Context.Service<
|
|
|
62
62
|
const db = yield* Database
|
|
63
63
|
const atomic = yield* AtomicBatch
|
|
64
64
|
const ids = yield* IdGenerator
|
|
65
|
-
const remembered =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
while (remembered.size >= REMEMBER_MAX) {
|
|
76
|
-
const oldest = remembered.keys().next().value
|
|
77
|
-
if (oldest === undefined) break
|
|
78
|
-
remembered.delete(oldest)
|
|
65
|
+
const remembered = yield* Cache.make<string, SessionUser>({
|
|
66
|
+
capacity: REMEMBER_MAX,
|
|
67
|
+
timeToLive: REMEMBER_TTL,
|
|
68
|
+
lookup: () => Effect.die(new Error('Session cache is populated explicitly via Cache.set.')),
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
const forgetUser = (userId: string) =>
|
|
72
|
+
Effect.gen(function* () {
|
|
73
|
+
for (const [id, user] of yield* Cache.entries(remembered)) {
|
|
74
|
+
if (user.id === userId) yield* Cache.invalidate(remembered, id)
|
|
79
75
|
}
|
|
80
|
-
}
|
|
81
|
-
remembered.set(sessionId, { user, until: nowMs + REMEMBER_MS })
|
|
82
|
-
}
|
|
76
|
+
})
|
|
83
77
|
|
|
84
78
|
return Sessions.of({
|
|
85
79
|
start: (userId, device = '') =>
|
|
@@ -102,8 +96,8 @@ export class Sessions extends Context.Service<
|
|
|
102
96
|
|
|
103
97
|
verify: (sessionId, options) =>
|
|
104
98
|
Effect.gen(function* () {
|
|
105
|
-
const known =
|
|
106
|
-
if (known
|
|
99
|
+
const known = yield* Cache.getOption(remembered, sessionId)
|
|
100
|
+
if (known._tag === 'Some') return known.value
|
|
107
101
|
|
|
108
102
|
const now = yield* DateTime.now
|
|
109
103
|
const nowStr = DateTime.formatIso(now)
|
|
@@ -141,19 +135,16 @@ export class Sessions extends Context.Service<
|
|
|
141
135
|
}
|
|
142
136
|
|
|
143
137
|
const user: SessionUser = { id: row.id, username: row.username, emailStatus: row.email_status }
|
|
144
|
-
|
|
138
|
+
yield* Cache.set(remembered, sessionId, user)
|
|
145
139
|
return user
|
|
146
140
|
}),
|
|
147
141
|
|
|
148
142
|
end: (sessionId) =>
|
|
149
|
-
Effect.
|
|
150
|
-
Effect.flatMap(() => db.run(`DELETE FROM sessions WHERE id = ?`, [sessionId]).pipe(Effect.orDie)),
|
|
151
|
-
),
|
|
143
|
+
Cache.invalidate(remembered, sessionId).pipe(Effect.andThen(db.run(`DELETE FROM sessions WHERE id = ?`, [sessionId]).pipe(Effect.orDie))),
|
|
152
144
|
|
|
153
|
-
endAll: (userId) =>
|
|
154
|
-
Effect.sync(() => forgetUser(userId)).pipe(Effect.flatMap(() => db.run(`DELETE FROM sessions WHERE user_id = ?`, [userId]).pipe(Effect.orDie))),
|
|
145
|
+
endAll: (userId) => forgetUser(userId).pipe(Effect.andThen(db.run(`DELETE FROM sessions WHERE user_id = ?`, [userId]).pipe(Effect.orDie))),
|
|
155
146
|
|
|
156
|
-
forget:
|
|
147
|
+
forget: forgetUser,
|
|
157
148
|
|
|
158
149
|
recent: (userId, currentId) =>
|
|
159
150
|
Effect.gen(function* () {
|