From b8ae731042488c34f42e23443c63333dccc279d1 Mon Sep 17 00:00:00 2001 From: Vincent Jaubert Date: Tue, 3 May 2022 22:48:51 +0200 Subject: [PATCH 1/2] Added Error to return type of async validator --- index.d.ts | 2 +- index.test-d.ts | 1 + 2 files changed, 2 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..d1d91cd 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -19,6 +19,7 @@ app.register(fastifyBasicAuth, { expectType(req) expectType(reply) expectType(this) + return new Error("unauthorized") }, header: 'x-forwarded-authorization' }) From 062f6d29e5b1e914c0044961a3522a38973999fd Mon Sep 17 00:00:00 2001 From: Vincent Jaubert Date: Wed, 4 May 2022 11:10:18 +0200 Subject: [PATCH 2/2] Split the promise validator tsd test --- index.test-d.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.test-d.ts b/index.test-d.ts index d1d91cd..bf205ca 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -12,6 +12,19 @@ import fastifyBasicAuth from '.' const app = fastify() +//validation ok +app.register(fastifyBasicAuth, { + validate: async function validatePromise (username, password, req, reply) { + expectType(username) + expectType(password) + expectType(req) + expectType(reply) + expectType(this) + }, + header: 'x-forwarded-authorization' +}) + +//validation failure app.register(fastifyBasicAuth, { validate: async function validatePromise (username, password, req, reply) { expectType(username) @@ -24,6 +37,8 @@ app.register(fastifyBasicAuth, { header: 'x-forwarded-authorization' }) + + app.register(fastifyBasicAuth, { validate: function validateCallback (username, password, req, reply, done) { expectType(username)