MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / clientHook

Function clientHook

apps/api/src/hooks/client.hook.ts:8–26  ·  view source on GitHub ↗
(
  req: FastifyRequest<{
    Body: ITrackHandlerPayload | DeprecatedPostEventPayload;
  }>,
  reply: FastifyReply,
)

Source from the content-addressed store, hash-verified

6import type { FastifyReply, FastifyRequest } from 'fastify';
7
8export async function clientHook(
9 req: FastifyRequest<{
10 Body: ITrackHandlerPayload | DeprecatedPostEventPayload;
11 }>,
12 reply: FastifyReply,
13) {
14 try {
15 const client = await validateSdkRequest(req);
16 req.client = client;
17 } catch (error) {
18 if (error instanceof SdkAuthError) {
19 req.log.warn({ err: error }, 'Invalid SDK request');
20 return reply.status(401).send(error.message);
21 }
22
23 req.log.error({ err: error }, 'Invalid SDK request');
24 return reply.status(500).send('Internal server error');
25 }
26}

Callers

nothing calls this directly

Calls 4

validateSdkRequestFunction · 0.90
warnMethod · 0.45
sendMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected