Fixed Wrong IP being loged
This commit is contained in:
@@ -26,6 +26,7 @@ export async function getOrSetDeviceId() {
|
||||
export const logAction = async (
|
||||
type: LOG_TYPE,
|
||||
otherValues?: {
|
||||
ip: string;
|
||||
field?: string;
|
||||
oldValue?: string;
|
||||
newValue?: string;
|
||||
@@ -35,13 +36,6 @@ export const logAction = async (
|
||||
const headersList = await headers();
|
||||
const user = await getServerSession();
|
||||
|
||||
console.log(Array.from(headersList.entries()));
|
||||
|
||||
const ip =
|
||||
headersList.get("X-Forwarded-For") ||
|
||||
headersList.get("Forwarded") ||
|
||||
headersList.get("X-Real-IP");
|
||||
|
||||
const deviceId = await getOrSetDeviceId();
|
||||
if (type == "LOGIN" || type == "REGISTER") {
|
||||
const existingLogs = await prisma.log.findMany({
|
||||
@@ -52,7 +46,7 @@ export const logAction = async (
|
||||
},
|
||||
OR: [
|
||||
{
|
||||
ip: ip,
|
||||
ip: otherValues?.ip,
|
||||
},
|
||||
{
|
||||
deviceId: deviceId,
|
||||
@@ -82,7 +76,7 @@ export const logAction = async (
|
||||
browser: headersList.get("user-agent") || "unknown",
|
||||
userId: user?.user.id || otherValues?.userId,
|
||||
deviceId: deviceId,
|
||||
ip,
|
||||
ip: otherValues?.ip,
|
||||
...otherValues,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user