diff --git a/apps/hub/app/(auth)/login/_components/action.ts b/apps/hub/app/(auth)/login/_components/action.ts index 87af797e..155a1ebc 100644 --- a/apps/hub/app/(auth)/login/_components/action.ts +++ b/apps/hub/app/(auth)/login/_components/action.ts @@ -26,9 +26,10 @@ export async function getOrSetDeviceId() { export const logAction = async ( type: LOG_TYPE, otherValues?: { - field: string; - oldValue: string; - newValue: string; + field?: string; + oldValue?: string; + newValue?: string; + userId?: string; }, ) => { const headersList = await headers(); @@ -40,7 +41,7 @@ export const logAction = async ( headersList.get("X-Real-IP"); const deviceId = await getOrSetDeviceId(); - if (type == "LOGIN") { + if (type == "LOGIN" || type == "REGISTER") { const existingLogs = await prisma.log.findMany({ where: { type: "LOGIN", @@ -77,7 +78,7 @@ export const logAction = async ( data: { type, browser: headersList.get("user-agent") || "unknown", - userId: user?.user.id, + userId: user?.user.id || otherValues?.userId, deviceId: deviceId, ip, ...otherValues, diff --git a/apps/hub/app/(auth)/register/_components/Register.tsx b/apps/hub/app/(auth)/register/_components/Register.tsx index 2990cdeb..0c67eb6e 100644 --- a/apps/hub/app/(auth)/register/_components/Register.tsx +++ b/apps/hub/app/(auth)/register/_components/Register.tsx @@ -9,6 +9,7 @@ import { useState } from "react"; import { Button } from "../../../_components/ui/Button"; import { sendVerificationLink } from "(app)/admin/user/action"; import toast from "react-hot-toast"; +import { logAction } from "(auth)/login/_components/action"; export const Register = () => { const schema = z @@ -93,6 +94,9 @@ export const Register = () => { return; } await sendVerificationLink(user.id); + await logAction("REGISTER", { + userId: user.id, + }); await signIn("credentials", { callbackUrl: "/", email: user.email, diff --git a/apps/hub/app/(auth)/register/action.ts b/apps/hub/app/(auth)/register/action.ts index 5404372b..6ba13948 100644 --- a/apps/hub/app/(auth)/register/action.ts +++ b/apps/hub/app/(auth)/register/action.ts @@ -53,5 +53,6 @@ export const register = async ({ password, ...user }: Omit