(request: FastifyRequest, reply: FastifyReply)
| 15 | } |
| 16 | |
| 17 | export async function authHook(request: FastifyRequest, reply: FastifyReply): Promise<void> { |
| 18 | const authHeader = request.headers.authorization |
| 19 | if (!authHeader || !authHeader.startsWith('Bearer ')) { |
| 20 | const err = unauthorized() |
| 21 | reply.code(err.statusCode).send(errorResponse(err)) |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | const token = authHeader.slice(7) |
| 26 | const config = getConfig() |
| 27 | |
| 28 | if (!config.token || !safeTokenCompare(token, config.token)) { |
| 29 | const err = unauthorized() |
| 30 | reply.code(err.statusCode).send(errorResponse(err)) |
| 31 | return |
| 32 | } |
| 33 | } |
nothing calls this directly
no test coverage detected