1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00
unleash.unleash/src/lib/middleware/audit-middleware.ts
Christopher Kolstad cf2bd28ff6
feat: use audit info in events (#6872)
I've tried to use/add the audit info to all events I could see/find.
This makes this PR necessarily huge, because we do store quite a few
events. 

I realise it might not be complete yet, but tests
run green, and I think we now have a pattern to follow for other events.
2024-04-18 16:32:35 +02:00

22 lines
701 B
TypeScript

import type { IUnleashConfig } from '../types';
import type { IApiRequest, IAuthRequest } from '../routes/unleash-types';
import { extractAuditInfo } from '../util';
export const auditAccessMiddleware = ({
getLogger,
}: Pick<IUnleashConfig, 'getLogger'>): any => {
const logger = getLogger('/middleware/audit-middleware.ts');
return (req: IAuthRequest | IApiRequest, _res, next) => {
if (!req.user) {
logger.info('Could not find user');
} else {
try {
req.audit = extractAuditInfo(req);
} catch (e) {
logger.warn('Could not find audit info in request');
}
}
next();
};
};