Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ declare module 'fastify' {
}

export interface FastifyBasicAuthOptions {
validate(
username: string,
password: string,
req: FastifyRequest,
reply: FastifyReply,
done: (err?: Error) => void
): void | Promise<void>;
validate: (
(
username: string,
password: string,
req: FastifyRequest,
reply: FastifyReply,
) => Promise<Error | void>
) | (
(
username: string,
password: string,
req: FastifyRequest,
reply: FastifyReply,
done: (err?: Error) => void
) => void
);
authenticate?: boolean | { realm: string };
header?: string;
}
Expand Down
1 change: 1 addition & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ app.register(fastifyBasicAuth, {
expectType<string>(password)
expectType<FastifyRequest>(req)
expectType<FastifyReply>(reply)
if (Math.random() > 0.5) return new Error()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this throw instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The document is using return and it is actually allowed by this line.

result.then(done, done)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer two asserts group instead:

  • One returning Promise<Error>
  • One returning Promise<void>

},
header: 'x-forwarded-authorization'
})
Expand Down