Skip to content

Commit

Permalink
Add missing options
Browse files Browse the repository at this point in the history
  • Loading branch information
francisdaigle committed May 21, 2021
1 parent f7480fa commit 18f63c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
}
]
}
6 changes: 5 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ declare module 'fastify' {
}

declare const fastifyGuard: FastifyPluginCallback<{
errorHandler(
errorHandler?(
result: createHttpError.HttpError,
request: FastifyRequest,
reply: FastifyReply
): any
requestProperty?: string
roleProperty?: string
scopeProperty?: string
}>

export default fastifyGuard
11 changes: 7 additions & 4 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ const fastify = Fastify()

fastify.register(fastifyGuard, {
errorHandler: (result, req, reply) => {
return reply.send('Custom error message')
}
return reply.send('string')
},
requestProperty: 'string',
roleProperty: 'string',
scopeProperty: 'string'
})

;(request: FastifyRequest, reply: FastifyReply) => {
Expand All @@ -26,5 +29,5 @@ fastify.register(fastifyGuard, {
)
}

expectType<preHandlerHookHandler>(fastify.guard.role(['user']))
expectType<preHandlerHookHandler>(fastify.guard.scope(['read']))
expectType<preHandlerHookHandler>(fastify.guard.role(['string']))
expectType<preHandlerHookHandler>(fastify.guard.scope(['string']))

0 comments on commit 18f63c3

Please sign in to comment.