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)