Skip to content

Commit

Permalink
chore: nuxt-modules#2 add types
Browse files Browse the repository at this point in the history
  • Loading branch information
felix committed Jun 25, 2024
1 parent c5dbd5c commit 0e28fe3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/runtime/auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import type { JWTPayload } from 'jose'

export type HankoPayload = JWTPayload & {
aud: string[]
email: {
address: string
is_primary: boolean
is_verified: boolean
}
exp: number
iat: number
sub: string
}

declare module 'h3' {
interface H3EventContext {
hanko?: JWTPayload
hanko?: HankoPayload
}
}
3 changes: 2 additions & 1 deletion src/runtime/server/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { H3Event } from 'h3'
import { createError, getCookie, getHeader } from 'h3'
import { createRemoteJWKSet, jwtVerify } from 'jose'
import { useRuntimeConfig } from '#imports'
import type { HankoPayload } from '../../auth'

export async function verifyHankoEvent(event: H3Event) {
const hankoConfig = useRuntimeConfig().public.hanko
Expand All @@ -17,5 +18,5 @@ export async function verifyHankoEvent(event: H3Event) {
})
}

return await jwtVerify(jwt, JWKS).then(r => r.payload)
return await jwtVerify<HankoPayload>(jwt, JWKS).then(r => r.payload)
}

0 comments on commit 0e28fe3

Please sign in to comment.