Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodenext compatiblity #110

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const MissingOrBadAuthorizationHeader = createError(
401
)

async function basicPlugin (fastify, opts) {
async function fastifyBasicAuth (fastify, opts) {
if (typeof opts.validate !== 'function') {
throw new Error('Basic Auth: Missing validate function')
}
Expand Down Expand Up @@ -80,7 +80,9 @@ function getAuthenticateHeader (authenticate) {
throw new Error('Basic Auth: Invalid authenticate option')
}

module.exports = fp(basicPlugin, {
module.exports = fp(fastifyBasicAuth, {
fastify: '4.x',
name: '@fastify/basic-auth'
})
module.exports.default = fastifyBasicAuth
module.exports.fastifyBasicAuth = fastifyBasicAuth
37 changes: 22 additions & 15 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,30 @@ import {
declare module 'fastify' {
interface FastifyInstance {
basicAuth: onRequestHookHandler |
preValidationHookHandler |
preHandlerHookHandler
preValidationHookHandler |
preHandlerHookHandler
}
}

export interface FastifyBasicAuthOptions {
validate(
this: FastifyInstance,
username: string,
password: string,
req: FastifyRequest,
reply: FastifyReply,
done: (err?: Error) => void
): void | Promise<void|Error>;
authenticate?: boolean | { realm: string | ((req: FastifyRequest) => string) };
header?: string;
type FastifyBasicAuth = FastifyPluginAsync<fastifyBasicAuth.FastifyBasicAuthOptions>

declare namespace fastifyBasicAuth {
export interface FastifyBasicAuthOptions {
validate(
this: FastifyInstance,
username: string,
password: string,
req: FastifyRequest,
reply: FastifyReply,
done: (err?: Error) => void
): void | Promise<void | Error>;
authenticate?: boolean | { realm: string | ((req: FastifyRequest) => string) };
header?: string;
}

export const fastifyBasicAuth: FastifyBasicAuth
export { fastifyBasicAuth as default }
}

declare const fastifyBasicAuth: FastifyPluginAsync<FastifyBasicAuthOptions>
export default fastifyBasicAuth;
declare function fastifyBasicAuth(...params: Parameters<FastifyBasicAuth>): ReturnType<FastifyBasicAuth>
export = fastifyBasicAuth