Skip to content

Commit

Permalink
types: add typings for realm function (fix #40) (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
crutch12 authored Sep 2, 2022
1 parent d0d5219 commit b66d5d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface FastifyBasicAuthOptions {
reply: FastifyReply,
done: (err?: Error) => void
): void | Promise<void|Error>;
authenticate?: boolean | { realm: string };
authenticate?: boolean | { realm: string | ((req: FastifyRequest) => string) };
header?: string;
}

Expand Down
20 changes: 20 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<onRequestHookHandler>(app.basicAuth)
expectAssignable<preValidationHookHandler>(app.basicAuth)
expectAssignable<preHandlerHookHandler>(app.basicAuth)

0 comments on commit b66d5d4

Please sign in to comment.