Skip to content

Commit b8c0a1d

Browse files
committed
Store IP in messageEvents
1 parent 7560449 commit b8c0a1d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/lib/types/MessageEvent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ import type { User } from "./User";
33

44
export interface MessageEvent extends Pick<Timestamps, "createdAt"> {
55
userId: User["_id"] | User["sessionId"];
6+
ip?: string;
67
}

src/routes/conversation/[id]/+server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { ObjectId } from "mongodb";
1818
import { z } from "zod";
1919
import { AwsClient } from "aws4fetch";
2020

21-
export async function POST({ request, fetch, locals, params }) {
21+
export async function POST({ request, fetch, locals, params, getClientAddress }) {
2222
const id = z.string().parse(params.id);
2323
const convId = new ObjectId(id);
2424
const date = new Date();
@@ -184,6 +184,7 @@ export async function POST({ request, fetch, locals, params }) {
184184
await collections.messageEvents.insertOne({
185185
userId: userId,
186186
createdAt: new Date(),
187+
ip: getClientAddress(),
187188
});
188189

189190
await collections.conversations.updateOne(

0 commit comments

Comments
 (0)