Skip to content

Commit b66d5d4

Browse files
authored
types: add typings for realm function (fix #40) (#105)
1 parent d0d5219 commit b66d5d4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface FastifyBasicAuthOptions {
2626
reply: FastifyReply,
2727
done: (err?: Error) => void
2828
): void | Promise<void|Error>;
29-
authenticate?: boolean | { realm: string };
29+
authenticate?: boolean | { realm: string | ((req: FastifyRequest) => string) };
3030
header?: string;
3131
}
3232

index.test-d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ app.register(fastifyBasicAuth, {
4949
}
5050
})
5151

52+
//authenticate boolean
53+
app.register(fastifyBasicAuth, {
54+
validate: () => {},
55+
authenticate: true
56+
})
57+
58+
//authenticate with realm
59+
app.register(fastifyBasicAuth, {
60+
validate: () => {},
61+
authenticate: { realm: 'example' }
62+
})
63+
64+
//authenticate with realm (function)
65+
app.register(fastifyBasicAuth, {
66+
validate: () => {},
67+
authenticate: { realm: function realm(req) {
68+
return req.routerPath
69+
}}
70+
})
71+
5272
expectAssignable<onRequestHookHandler>(app.basicAuth)
5373
expectAssignable<preValidationHookHandler>(app.basicAuth)
5474
expectAssignable<preHandlerHookHandler>(app.basicAuth)

0 commit comments

Comments
 (0)