fix(06): log audit events and set Viewed status in signing page server component
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { verifySigningToken } from '@/lib/signing/token';
|
||||
import { logAuditEvent } from '@/lib/signing/audit';
|
||||
import { db } from '@/lib/db';
|
||||
import { signingTokens, documents } from '@/lib/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { headers } from 'next/headers';
|
||||
import { SigningPageClientWrapper } from './_components/SigningPageClientWrapper';
|
||||
|
||||
interface Props {
|
||||
@@ -45,6 +47,16 @@ export default async function SignPage({ params }: Props) {
|
||||
|
||||
if (!doc || !doc.preparedFilePath) return <ErrorPage type="invalid" />;
|
||||
|
||||
// Log audit events and update status to Viewed
|
||||
const headersList = await headers();
|
||||
const ip = headersList.get('x-forwarded-for')?.split(',')[0].trim() ?? 'unknown';
|
||||
const ua = headersList.get('user-agent') ?? 'unknown';
|
||||
await Promise.all([
|
||||
logAuditEvent({ documentId: payload.documentId, eventType: 'link_opened', ipAddress: ip, userAgent: ua }),
|
||||
logAuditEvent({ documentId: payload.documentId, eventType: 'document_viewed', ipAddress: ip, userAgent: ua }),
|
||||
db.update(documents).set({ status: 'Viewed' }).where(eq(documents.id, payload.documentId)),
|
||||
]);
|
||||
|
||||
return (
|
||||
<SigningPageClientWrapper
|
||||
token={token}
|
||||
|
||||
Reference in New Issue
Block a user