Skip to content

Commit e7eaa28

Browse files
authored
chore: fix types (#393)
1 parent acf94d9 commit e7eaa28

File tree

27 files changed

+253
-117
lines changed

27 files changed

+253
-117
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ jobs:
6565
- name: Run test suite
6666
run: pnpm test
6767

68-
# - name: Test types
69-
# run: pnpm test:types
68+
- name: Test types
69+
run: pnpm test:types
7070

7171
# - name: Test playground types
7272
# run: pnpm test:types:playground

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lint:fix": "eslint . --fix",
3232
"test": "vitest run",
3333
"test:types": "vue-tsc --noEmit",
34-
"test:types:playground": "cd playground && vue-tsc --noEmit",
34+
"test:types:playground": "nuxt typecheck playground",
3535
"test:watch": "vitest watch"
3636
},
3737
"dependencies": {

playground/components/AuthLogin.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const isOpen = ref(false)
44
const { fetch, user } = useUserSession()
55
const toast = useToast()
66
7-
async function login(event: SubmitEvent) {
7+
async function login(event: Event) {
88
const target = event.target as HTMLFormElement
99
1010
await $fetch('/api/login', {

playground/components/AuthRegister.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const isOpen = ref(false)
44
const { fetch, user } = useUserSession()
55
const toast = useToast()
66
7-
async function register(event: SubmitEvent) {
7+
async function register(event: Event) {
88
const target = event.target as HTMLFormElement
99
1010
await $fetch('/api/register', {

playground/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,5 @@
2020
},
2121
"devDependencies": {
2222
"better-sqlite3": "^11.8.1"
23-
},
24-
"resolutions": {
25-
"h3": "^1.14.0"
2623
}
2724
}

playground/server/api/webauthn/authenticate.post.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default defineWebAuthnAuthenticateEventHandler({
3737
},
3838
async onSuccess(event, { credential, authenticationInfo }) {
3939
const db = useDatabase()
40-
const { rows } = await db.sql<{ rows: string[] }>`
40+
const { rows } = await db.sql<{ rows: { email: string }[] }>`
4141
SELECT users.email
4242
FROM credentials
4343
INNER JOIN users ON users.id = credentials.userId

playground/server/api/webauthn/register.post.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default defineWebAuthnRegisterEventHandler({
1717
const db = useDatabase()
1818
try {
1919
await db.sql`BEGIN TRANSACTION`
20+
// @ts-expect-error - dbUser is not defined in the type
2021
let { rows: [dbUser] } = await db.sql`SELECT * FROM users WHERE email = ${user.userName}`
2122
if (!dbUser) {
2223
await db.sql`INSERT INTO users (email) VALUES (${user.userName})`
@@ -50,7 +51,7 @@ export default defineWebAuthnRegisterEventHandler({
5051
await db.sql`ROLLBACK`
5152
throw createError({
5253
statusCode: 500,
53-
message: err.message.includes('UNIQUE constraint failed') ? 'User already registered' : 'Failed to store credential',
54+
message: err instanceof Error && err.message.includes('UNIQUE constraint failed') ? 'User already registered' : 'Failed to store credential',
5455
})
5556
}
5657
},

pnpm-lock.yaml

Lines changed: 166 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
packages:
22
- "playground"
3+
- "./"

src/runtime/app/composables/session.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { UserSession, UserSessionComposable } from '#auth-utils'
88
*/
99
export function useUserSession(): UserSessionComposable {
1010
const serverEvent = import.meta.server ? useRequestEvent() : null
11-
const sessionState = useState<UserSession>('nuxt-session', () => ({}))
11+
const sessionState = useState<UserSession | null>('nuxt-session', () => null)
1212
const authReadyState = useState('nuxt-auth-ready', () => false)
1313

1414
const clear = async () => {
@@ -23,16 +23,16 @@ export function useUserSession(): UserSessionComposable {
2323
}
2424
},
2525
})
26-
sessionState.value = {}
26+
sessionState.value = null
2727
}
2828

2929
const fetch = async () => {
30-
sessionState.value = await useRequestFetch()('/api/_auth/session', {
30+
sessionState.value = await useRequestFetch()<UserSession>('/api/_auth/session', {
3131
headers: {
3232
accept: 'application/json',
3333
},
3434
retry: false,
35-
}).catch(() => ({}))
35+
}).catch(() => null)
3636
if (!authReadyState.value) {
3737
authReadyState.value = true
3838
}
@@ -68,8 +68,8 @@ export function useUserSession(): UserSessionComposable {
6868

6969
return {
7070
ready: computed(() => authReadyState.value),
71-
loggedIn: computed(() => Boolean(sessionState.value.user)),
72-
user: computed(() => sessionState.value.user || null),
71+
loggedIn: computed(() => Boolean(sessionState.value?.user)),
72+
user: computed(() => sessionState.value?.user || null),
7373
session: sessionState,
7474
fetch,
7575
openInPopup,

0 commit comments

Comments
 (0)