Add AuditLog table and Prisma audit extension
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { AsyncLocalStorage } from 'node:async_hooks';
|
||||
|
||||
/**
|
||||
* The actor for the current request, used by the Prisma audit extension to
|
||||
* attribute database mutations. Populated in `hooks.server.ts`.
|
||||
*/
|
||||
export type AuditContext = {
|
||||
userId: string | null;
|
||||
email: string | null;
|
||||
roleId: number | null;
|
||||
page: string;
|
||||
ip: string | null;
|
||||
};
|
||||
|
||||
const storage = new AsyncLocalStorage<AuditContext>();
|
||||
|
||||
export function runWithAuditContext<T>(context: AuditContext, fn: () => T): T {
|
||||
return storage.run(context, fn);
|
||||
}
|
||||
|
||||
export function getAuditContext(): AuditContext | undefined {
|
||||
return storage.getStore();
|
||||
}
|
||||
Reference in New Issue
Block a user