UNPKG

1.08 kBPlain TextView Raw
1import { expectType } from 'tsd'
2import createHttpError from 'http-errors'
3
4import Fastify, {
5 FastifyReply,
6 FastifyRequest,
7 preHandlerHookHandler
8} from 'fastify'
9import fastifyGuard from '.'
10
11const fastify = Fastify()
12
13fastify.register(fastifyGuard, {
14 errorHandler: (result, req, reply) => {
15 return reply.send('string')
16 },
17 requestProperty: 'string',
18 roleProperty: 'string',
19 scopeProperty: 'string'
20})
21
22;(request: FastifyRequest, reply: FastifyReply) => {
23 expectType<boolean | createHttpError.HttpError>(
24 fastify.guard.hasRole(request, 'user')
25 )
26
27 expectType<boolean | createHttpError.HttpError>(
28 fastify.guard.hasScope(request, 'read')
29 )
30}
31expectType<preHandlerHookHandler>(fastify.guard.role('ceo'))
32expectType<preHandlerHookHandler>(fastify.guard.role('ceo', 'cto'))
33expectType<preHandlerHookHandler>(fastify.guard.role(['string']))
34expectType<preHandlerHookHandler>(fastify.guard.scope('profile'))
35expectType<preHandlerHookHandler>(fastify.guard.scope('profile', 'blog'))
36expectType<preHandlerHookHandler>(fastify.guard.scope(['string']))