From 7ec8a6dddfcbe8e30ccf3d7872c69dc3addcda53 Mon Sep 17 00:00:00 2001 From: Vincent Jaubert Date: Wed, 4 May 2022 11:29:09 +0200 Subject: [PATCH] Added Error to return type of async validator (#89) * Added Error to return type of async validator * Split the promise validator tsd test --- index.d.ts | 2 +- index.test-d.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 053e2ca..e1604ab 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,7 +25,7 @@ export interface FastifyBasicAuthOptions { req: FastifyRequest, reply: FastifyReply, done: (err?: Error) => void - ): void | Promise; + ): void | Promise; authenticate?: boolean | { realm: string }; header?: string; } diff --git a/index.test-d.ts b/index.test-d.ts index c2326bf..bf205ca 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -12,6 +12,7 @@ import fastifyBasicAuth from '.' const app = fastify() +//validation ok app.register(fastifyBasicAuth, { validate: async function validatePromise (username, password, req, reply) { expectType(username) @@ -23,6 +24,21 @@ app.register(fastifyBasicAuth, { header: 'x-forwarded-authorization' }) +//validation failure +app.register(fastifyBasicAuth, { + validate: async function validatePromise (username, password, req, reply) { + expectType(username) + expectType(password) + expectType(req) + expectType(reply) + expectType(this) + return new Error("unauthorized") + }, + header: 'x-forwarded-authorization' +}) + + + app.register(fastifyBasicAuth, { validate: function validateCallback (username, password, req, reply, done) { expectType(username)