Added Account log for registration
This commit is contained in:
@@ -26,9 +26,10 @@ export async function getOrSetDeviceId() {
|
|||||||
export const logAction = async (
|
export const logAction = async (
|
||||||
type: LOG_TYPE,
|
type: LOG_TYPE,
|
||||||
otherValues?: {
|
otherValues?: {
|
||||||
field: string;
|
field?: string;
|
||||||
oldValue: string;
|
oldValue?: string;
|
||||||
newValue: string;
|
newValue?: string;
|
||||||
|
userId?: string;
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
const headersList = await headers();
|
const headersList = await headers();
|
||||||
@@ -40,7 +41,7 @@ export const logAction = async (
|
|||||||
headersList.get("X-Real-IP");
|
headersList.get("X-Real-IP");
|
||||||
|
|
||||||
const deviceId = await getOrSetDeviceId();
|
const deviceId = await getOrSetDeviceId();
|
||||||
if (type == "LOGIN") {
|
if (type == "LOGIN" || type == "REGISTER") {
|
||||||
const existingLogs = await prisma.log.findMany({
|
const existingLogs = await prisma.log.findMany({
|
||||||
where: {
|
where: {
|
||||||
type: "LOGIN",
|
type: "LOGIN",
|
||||||
@@ -77,7 +78,7 @@ export const logAction = async (
|
|||||||
data: {
|
data: {
|
||||||
type,
|
type,
|
||||||
browser: headersList.get("user-agent") || "unknown",
|
browser: headersList.get("user-agent") || "unknown",
|
||||||
userId: user?.user.id,
|
userId: user?.user.id || otherValues?.userId,
|
||||||
deviceId: deviceId,
|
deviceId: deviceId,
|
||||||
ip,
|
ip,
|
||||||
...otherValues,
|
...otherValues,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { useState } from "react";
|
|||||||
import { Button } from "../../../_components/ui/Button";
|
import { Button } from "../../../_components/ui/Button";
|
||||||
import { sendVerificationLink } from "(app)/admin/user/action";
|
import { sendVerificationLink } from "(app)/admin/user/action";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
import { logAction } from "(auth)/login/_components/action";
|
||||||
|
|
||||||
export const Register = () => {
|
export const Register = () => {
|
||||||
const schema = z
|
const schema = z
|
||||||
@@ -93,6 +94,9 @@ export const Register = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await sendVerificationLink(user.id);
|
await sendVerificationLink(user.id);
|
||||||
|
await logAction("REGISTER", {
|
||||||
|
userId: user.id,
|
||||||
|
});
|
||||||
await signIn("credentials", {
|
await signIn("credentials", {
|
||||||
callbackUrl: "/",
|
callbackUrl: "/",
|
||||||
email: user.email,
|
email: user.email,
|
||||||
|
|||||||
@@ -53,5 +53,6 @@ export const register = async ({ password, ...user }: Omit<Prisma.UserCreateInpu
|
|||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return newUser;
|
return newUser;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user