UNPKG

942 BTypeScriptView Raw
1import createHttpError from 'http-errors'
2import {
3 FastifyPluginCallback,
4 FastifyReply,
5 FastifyRequest,
6 preHandlerHookHandler
7} from 'fastify'
8
9interface FastifyGuard {
10 hasRole(
11 request: FastifyRequest,
12 role: string
13 ): boolean | createHttpError.HttpError
14 hasScope(
15 request: FastifyRequest,
16 scope: string
17 ): boolean | createHttpError.HttpError
18 role(...roles: string[]): preHandlerHookHandler
19 role(roles: string[]): preHandlerHookHandler
20 scope(...scopes: string[]): preHandlerHookHandler
21 scope(scopes: string[]): preHandlerHookHandler
22}
23
24declare module 'fastify' {
25 interface FastifyInstance {
26 guard: FastifyGuard
27 }
28}
29
30declare const fastifyGuard: FastifyPluginCallback<{
31 errorHandler?(
32 result: createHttpError.HttpError,
33 request: FastifyRequest,
34 reply: FastifyReply
35 ): any
36 requestProperty?: string
37 roleProperty?: string
38 scopeProperty?: string
39}>
40
41export default fastifyGuard