Skip to content

Commit f18025a

Browse files
authored
chore(index): add jsdoc types (#177)
1 parent a21a9e7 commit f18025a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const fp = require('fastify-plugin')
44
const createError = require('@fastify/error')
55

6+
/** @typedef {import('./types/index').FastifyBasicAuthOptions} FastifyBasicAuthOptions */
7+
68
/**
79
* HTTP provides a simple challenge-response authentication framework
810
* that can be used by a server to challenge a client request and by a
@@ -59,6 +61,7 @@ const controlRE = /[\x00-\x1F\x7F]/
5961

6062
const userPassRE = /^([^:]*):(.*)$/
6163

64+
/** @type {typeof import('./types/index').fastifyBasicAuth} */
6265
async function fastifyBasicAuth (fastify, opts) {
6366
if (typeof opts.validate !== 'function') {
6467
throw new Error('Basic Auth: Missing validate function')
@@ -144,6 +147,13 @@ async function fastifyBasicAuth (fastify, opts) {
144147
}
145148
}
146149

150+
/**
151+
* Generates a function that returns the appropriate authentication header.
152+
* @param {FastifyBasicAuthOptions['authenticate']} authenticate - The authenticate option.
153+
* @param {FastifyBasicAuthOptions['utf8']} useUtf8 - Whether to use UTF-8 charset.
154+
* @param {FastifyBasicAuthOptions['proxyMode']} proxyMode - Whether in proxy mode.
155+
* @returns {(req: import('fastify').FastifyRequest) => false | [string, string]} Function that returns header tuple or false.
156+
*/
147157
function getAuthenticateHeaders (authenticate, useUtf8, proxyMode) {
148158
const defaultHeaderName = proxyMode ? 'Proxy-Authenticate' : 'WWW-Authenticate'
149159
if (!authenticate) return () => false

0 commit comments

Comments
 (0)