MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / authHook

Function authHook

apps/desktop/main/api/auth.ts:17–33  ·  view source on GitHub ↗
(request: FastifyRequest, reply: FastifyReply)

Source from the content-addressed store, hash-verified

15}
16
17export 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}

Callers

nothing calls this directly

Calls 4

unauthorizedFunction · 0.90
errorResponseFunction · 0.90
getConfigFunction · 0.90
safeTokenCompareFunction · 0.70

Tested by

no test coverage detected