You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

3 years ago
import fastify, { FastifyRequest, FastifyReply, preHandlerHookHandler, FastifyInstance } from 'fastify';
import fastifyAuth from '../auth'
import { expectType } from 'tsd';
const app = fastify();
type Done = (error?: Error) => void
app.register(fastifyAuth).after((err) => {
app.auth([
(request, reply, done) => {
expectType<FastifyRequest>(request)
expectType<FastifyReply>(reply)
expectType<Done>(done)
},
], {relation: 'or'});
app.auth([
(request, reply, done) => {
expectType<FastifyRequest>(request)
expectType<FastifyReply>(reply)
expectType<Done>(done)
},
], {run: 'all'});
app.auth([
(request, reply, done) => {
expectType<FastifyRequest>(request)
expectType<FastifyReply>(reply)
expectType<Done>(done)
},
]);
app.auth([
function (request, reply, done) {
expectType<FastifyInstance>(this)
},
]);
const auth = app.auth([(request, reply, done) => {}]);
expectType<preHandlerHookHandler>(auth);
app.get('/secret', {preHandler: auth}, (request, reply) => {});
app.get('/private', {preHandler: [auth]}, (request, reply) => {});
});