Skip to content

Commit 1de806b

Browse files
committed
chore ts fixes
1 parent 618579c commit 1de806b

8 files changed

Lines changed: 106 additions & 101 deletions

File tree

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nuxt-users",
33
"version": "1.0.0",
44
"description": "Nuxt users module",
5-
"repository": "your-org/nuxt-users",
5+
"repository": "rrd108/nuxt-users",
66
"license": "MIT",
77
"type": "module",
88
"exports": {
@@ -33,18 +33,18 @@
3333
"lint": "eslint .",
3434
"lint:fix": "eslint . --fix",
3535
"pretest": "node -v | grep -q 'v22' || (echo 'Please use Node.js v22 for deployment' && exit 1)",
36-
"test": "yarn test:sqlite && yarn test:mysql && yarn test:postgresql",
36+
"test": "yarn test:types && yarn test:sqlite && yarn test:mysql && yarn test:postgresql",
3737
"test:watch": "vitest watch",
3838
"test:sqlite": "./scripts/test-sqlite.sh",
3939
"test:mysql": "./scripts/test-mysql.sh",
4040
"test:postgresql": "./scripts/test-postgresql.sh",
4141
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
42-
"db:create-users-table": "tsx src/runtime/server/utils/create-users-table.ts",
43-
"db:create-user": "tsx src/runtime/server/utils/create-user.ts",
44-
"db:create-personal-access-tokens-table": "tsx src/runtime/server/utils/create-personal-access-tokens-table.ts",
45-
"db:create-password-reset-tokens-table": "tsx src/runtime/server/utils/create-password-reset-tokens-table.ts",
46-
"db:create-migrations-table": "tsx src/runtime/server/utils/create-migrations-table.ts",
47-
"db:migrate": "tsx src/runtime/server/utils/migrate.ts",
42+
"db:create-users-table": "tsx src/cli/create-users-table.ts",
43+
"db:create-user": "tsx src/cli/create-user.ts",
44+
"db:create-personal-access-tokens-table": "tsx src/cli/create-personal-access-tokens-table.ts",
45+
"db:create-password-reset-tokens-table": "tsx src/cli/create-password-reset-tokens-table.ts",
46+
"db:create-migrations-table": "tsx src/cli/create-migrations-table.ts",
47+
"db:migrate": "tsx src/cli/migrate.ts",
4848
"docs:dev": "vitepress dev docs",
4949
"docs:build": "vitepress build docs",
5050
"docs:preview": "vitepress preview docs"
@@ -55,6 +55,7 @@
5555
"@types/pg": "^8.15.4",
5656
"bcrypt": "^6.0.0",
5757
"better-sqlite3": "^12.2.0",
58+
"defu": "^6.1.4",
5859
"mysql2": "^3.14.2",
5960
"nodemailer": "^7.0.5",
6061
"pg": "^8.16.3",

src/runtime/components/ForgotPasswordForm.vue

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,3 @@
1-
<template>
2-
<div>
3-
<h2>Forgot Password</h2>
4-
<FormKit
5-
v-slot="{ disabled }"
6-
type="form"
7-
:actions="false"
8-
@submit="handleForgotPassword"
9-
>
10-
<FormKit
11-
v-model="formData.email"
12-
type="email"
13-
name="email"
14-
label="Email"
15-
placeholder="your@email.com"
16-
validation="required|email"
17-
/>
18-
<FormKit
19-
type="submit"
20-
:label="loading ? 'Sending...' : 'Send Password Reset Link'"
21-
:disabled="disabled || loading"
22-
/>
23-
<p
24-
v-if="message"
25-
:class="{ error: isError, success: !isError }"
26-
class="form-message"
27-
>
28-
{{ message }}
29-
</p>
30-
</FormKit>
31-
</div>
32-
</template>
33-
341
<script setup lang="ts">
352
import { ref, reactive } from 'vue'
363
// Ensure FormKit types are available if you're using them explicitly,
@@ -89,6 +56,39 @@ const handleForgotPassword = async (data: ForgotPasswordFormData) => {
8956
}
9057
</script>
9158

59+
<template>
60+
<div>
61+
<h2>Forgot Password</h2>
62+
<FormKit
63+
v-slot="{ disabled }"
64+
type="form"
65+
:actions="false"
66+
@submit="handleForgotPassword"
67+
>
68+
<FormKit
69+
v-model="formData.email"
70+
type="email"
71+
name="email"
72+
label="Email"
73+
placeholder="your@email.com"
74+
validation="required|email"
75+
/>
76+
<FormKit
77+
type="submit"
78+
:label="loading ? 'Sending...' : 'Send Password Reset Link'"
79+
:disabled="Boolean(disabled) || loading"
80+
/>
81+
<p
82+
v-if="message"
83+
:class="{ error: isError, success: !isError }"
84+
class="form-message"
85+
>
86+
{{ message }}
87+
</p>
88+
</FormKit>
89+
</div>
90+
</template>
91+
9292
<style scoped>
9393
.error {
9494
color: red;

src/runtime/components/LoginForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { ref } from 'vue'
33
import { navigateTo } from '#app'
4-
import type { LoginFormData, LoginFormProps, User } from '~/src/types'
4+
import type { LoginFormData, LoginFormProps, User } from '../../types'
55
66
interface Emits {
77
(e: 'success', user: User): void

src/runtime/components/ResetPasswordForm.vue

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,3 @@
1-
<template>
2-
<div>
3-
<h2>Reset Password</h2>
4-
<FormKit
5-
v-slot="{ disabled }"
6-
v-model="formData"
7-
type="form"
8-
:actions="false"
9-
@submit="handleResetPassword"
10-
>
11-
<FormKit
12-
type="password"
13-
name="password"
14-
label="New Password"
15-
validation="required|length:8"
16-
placeholder="Enter new password"
17-
/>
18-
<FormKit
19-
type="password"
20-
name="password_confirm"
21-
label="Confirm New Password"
22-
placeholder="Confirm new password"
23-
validation="required|confirm"
24-
validation-label="Password confirmation"
25-
/>
26-
<FormKit
27-
type="submit"
28-
:label="loading ? 'Resetting...' : 'Reset Password'"
29-
:disabled="disabled || loading || formInvalidDueToToken"
30-
/>
31-
<p
32-
v-if="message"
33-
:class="{ error: isError, success: !isError }"
34-
class="form-message"
35-
>
36-
{{ message }}
37-
</p>
38-
</FormKit>
39-
</div>
40-
</template>
41-
421
<script setup lang="ts">
432
import { ref, reactive, onMounted, computed } from 'vue'
443
import { useRoute, useRouter } from '#app' // Nuxt 3 specific imports
@@ -143,6 +102,47 @@ const handleResetPassword = async (data: ResetPasswordFormData) => {
143102
}
144103
</script>
145104

105+
<template>
106+
<div>
107+
<h2>Reset Password</h2>
108+
<FormKit
109+
v-slot="{ disabled }"
110+
v-model="formData"
111+
type="form"
112+
:actions="false"
113+
@submit="handleResetPassword"
114+
>
115+
<FormKit
116+
type="password"
117+
name="password"
118+
label="New Password"
119+
validation="required|length:8"
120+
placeholder="Enter new password"
121+
/>
122+
<FormKit
123+
type="password"
124+
name="password_confirm"
125+
label="Confirm New Password"
126+
placeholder="Confirm new password"
127+
validation="required|confirm"
128+
validation-label="Password confirmation"
129+
/>
130+
<FormKit
131+
type="submit"
132+
:label="loading ? 'Resetting...' : 'Reset Password'"
133+
:disabled="Boolean(disabled) || loading || formInvalidDueToToken"
134+
/>
135+
<p
136+
v-if="message"
137+
:class="{ error: isError, success: !isError }"
138+
class="form-message"
139+
>
140+
{{ message }}
141+
</p>
142+
</FormKit>
143+
</div>
144+
</template>
145+
146146
<style scoped>
147147
.error {
148148
color: red;

src/runtime/server/api/auth/reset-password.post.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { defineEventHandler, readBody, createError, H3Error } from 'h3'
22
import { resetPassword } from '../../services/password' // Adjusted path
3+
import type { ModuleOptions } from '../../../../types'
4+
import { useRuntimeConfig } from '#imports'
35

46
export default defineEventHandler(async (event) => {
57
const body = await readBody(event)
@@ -23,7 +25,8 @@ export default defineEventHandler(async (event) => {
2325
}
2426

2527
try {
26-
const success = await resetPassword(token, email, password, event)
28+
const options = useRuntimeConfig().nuxtUsers as ModuleOptions
29+
const success = await resetPassword(token, email, password, options)
2730

2831
if (success) {
2932
return { message: 'Password has been reset successfully. You can now log in with your new password.' }

src/runtime/server/api/login.post.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createDatabase } from 'db0'
44
import bcrypt from 'bcrypt'
55
import crypto from 'node:crypto'
66
import type { ModuleOptions, User } from '../../../types'
7+
import { useRuntimeConfig } from '#imports'
78

89
export default defineEventHandler(async (event) => {
910
const body = await readBody(event)

test/cli.create-user.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ describe('CLI: Create User', () => {
6666
const user = result.rows?.[0]
6767

6868
expect(user).toBeDefined()
69-
expect(user.email).toBe(userData.email)
70-
expect(user.name).toBe(userData.name)
71-
expect(user.id).toBe(1)
72-
expect(user.created_at).toBeDefined()
69+
expect(user?.email).toBe(userData.email)
70+
expect(user?.name).toBe(userData.name)
71+
expect(user?.id).toBe(1)
72+
expect(user?.created_at).toBeDefined()
7373
})
7474

7575
it('should hash the password correctly', async () => {
@@ -83,7 +83,7 @@ describe('CLI: Create User', () => {
8383

8484
// Get the stored password
8585
const result = await db.sql`SELECT password FROM users WHERE email = ${userData.email}`
86-
const storedPassword = result.rows?.[0]?.password
86+
const storedPassword = result.rows?.[0]?.password as string
8787

8888
expect(storedPassword).toBeDefined()
8989
expect(storedPassword).not.toBe(userData.password) // Should be hashed
@@ -124,19 +124,19 @@ describe('CLI: Create User', () => {
124124
const result = await db.sql`SELECT created_at, updated_at FROM users WHERE email = ${userData.email}`
125125
const user = result.rows?.[0]
126126

127-
expect(user.created_at).toBeDefined()
128-
expect(user.updated_at).toBeDefined()
127+
expect(user?.created_at).toBeDefined()
128+
expect(user?.updated_at).toBeDefined()
129129

130130
// Check that timestamps are valid dates
131-
const createdAt = new Date(user.created_at)
132-
const updatedAt = new Date(user.updated_at)
131+
const createdAt = new Date(user?.created_at as string)
132+
const updatedAt = new Date(user?.updated_at as string)
133133

134134
expect(createdAt.toString()).not.toBe('Invalid Date')
135135
expect(updatedAt.toString()).not.toBe('Invalid Date')
136136

137137
// Check that timestamps are not null/undefined
138-
expect(user.created_at).not.toBeNull()
139-
expect(user.updated_at).not.toBeNull()
138+
expect(user?.created_at).not.toBeNull()
139+
expect(user?.updated_at).not.toBeNull()
140140
})
141141

142142
it('should throw error for duplicate email', async () => {
@@ -181,7 +181,7 @@ describe('CLI: Create User', () => {
181181
const user = result.rows?.[0]
182182

183183
expect(user).toBeDefined()
184-
expect(user.email).toBe(userData.email)
185-
expect(user.name).toBe(userData.name)
184+
expect(user?.email).toBe(userData.email)
185+
expect(user?.name).toBe(userData.name)
186186
})
187187
})

test/cli.create-users-table.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ describe('CLI: Create Users Table', () => {
148148
const result = await db.sql`SELECT created_at, updated_at FROM {${testOptions.tables.users}} WHERE email = 'test@webmania.cc'`
149149
const user = result.rows?.[0]
150150

151-
expect(user.created_at).toBeDefined()
152-
expect(user.updated_at).toBeDefined()
153-
expect(user.created_at).not.toBeNull()
154-
expect(user.updated_at).not.toBeNull()
151+
expect(user?.created_at).toBeDefined()
152+
expect(user?.updated_at).toBeDefined()
153+
expect(user?.created_at).not.toBeNull()
154+
expect(user?.updated_at).not.toBeNull()
155155
})
156156

157157
it('should handle table creation with all constraints', async () => {

0 commit comments

Comments
 (0)