feature(dashboard): add ability to filter out events by profile id and ip (#101)
This commit is contained in:
committed by
GitHub
parent
27ee623584
commit
f4ad97d87d
@@ -1,20 +1,9 @@
|
||||
import { SdkAuthError, validateSdkRequest } from '@/utils/auth';
|
||||
import type { TrackHandlerPayload } from '@openpanel/sdk';
|
||||
import type {
|
||||
FastifyReply,
|
||||
FastifyRequest,
|
||||
HookHandlerDoneFunction,
|
||||
} from 'fastify';
|
||||
import type { FastifyReply, FastifyRequest } from 'fastify';
|
||||
|
||||
export async function clientHook(
|
||||
req: FastifyRequest<{
|
||||
Body: TrackHandlerPayload;
|
||||
}>,
|
||||
reply: FastifyReply,
|
||||
) {
|
||||
export async function clientHook(req: FastifyRequest, reply: FastifyReply) {
|
||||
try {
|
||||
const client = await validateSdkRequest(req.headers);
|
||||
req.projectId = client.projectId;
|
||||
const client = await validateSdkRequest(req);
|
||||
req.client = client;
|
||||
} catch (error) {
|
||||
if (error instanceof SdkAuthError) {
|
||||
|
||||
18
apps/api/src/hooks/ip.hook.ts
Normal file
18
apps/api/src/hooks/ip.hook.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { getClientIp } from '@/utils/parseIp';
|
||||
import type {
|
||||
FastifyReply,
|
||||
FastifyRequest,
|
||||
HookHandlerDoneFunction,
|
||||
} from 'fastify';
|
||||
|
||||
export function ipHook(
|
||||
request: FastifyRequest,
|
||||
reply: FastifyReply,
|
||||
done: HookHandlerDoneFunction,
|
||||
) {
|
||||
const ip = getClientIp(request);
|
||||
if (ip) {
|
||||
request.clientIp = ip;
|
||||
}
|
||||
done();
|
||||
}
|
||||
Reference in New Issue
Block a user