feat: add user security audit logs

This commit is contained in:
David Nguyen
2024-01-30 17:31:27 +11:00
parent 620ae41fcc
commit 7e15058a3a
32 changed files with 787 additions and 182 deletions

View File

@ -0,0 +1,22 @@
import type { NextApiRequest } from 'next';
import { z } from 'zod';
const ZIpSchema = z.string().ip();
export type RequestMetadata = {
ipAddress?: string;
userAgent?: string;
};
export const extractRequestMetadata = (req: NextApiRequest): RequestMetadata => {
const parsedIp = ZIpSchema.safeParse(req.headers['x-forwarded-for'] || req.socket.remoteAddress);
const ipAddress = parsedIp.success ? parsedIp.data : undefined;
const userAgent = req.headers['user-agent'];
return {
ipAddress,
userAgent,
};
};