From f5f84d77ac2dbc617da1fb003c1324003d3ac7a3 Mon Sep 17 00:00:00 2001 From: Konstantin Barabanov Date: Fri, 2 Sep 2022 15:35:55 +0300 Subject: [PATCH] types: add typings for realm function (fix #40) --- index.d.ts | 2 +- index.test-d.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index e1604ab..fdc8465 100644 --- a/index.d.ts +++ b/index.d.ts @@ -26,7 +26,7 @@ export interface FastifyBasicAuthOptions { reply: FastifyReply, done: (err?: Error) => void ): void | Promise; - authenticate?: boolean | { realm: string }; + authenticate?: boolean | { realm: string | ((req: FastifyRequest) => string) }; header?: string; } diff --git a/index.test-d.ts b/index.test-d.ts index 3937a28..e24a56c 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -49,6 +49,26 @@ app.register(fastifyBasicAuth, { } }) +//authenticate boolean +app.register(fastifyBasicAuth, { + validate: () => {}, + authenticate: true +}) + +//authenticate with realm +app.register(fastifyBasicAuth, { + validate: () => {}, + authenticate: { realm: 'example' } +}) + +//authenticate with realm (function) +app.register(fastifyBasicAuth, { + validate: () => {}, + authenticate: { realm: function realm(req) { + return req.routerPath + }} +}) + expectAssignable(app.basicAuth) expectAssignable(app.basicAuth) expectAssignable(app.basicAuth)