completed Account Log
This commit is contained in:
@@ -3,6 +3,7 @@ import { LOG_TYPE, prisma } from "@repo/db";
|
||||
import { getServerSession } from "api/auth/[...nextauth]/auth";
|
||||
import { randomUUID } from "crypto";
|
||||
import { cookies, headers } from "next/headers";
|
||||
import { sendReportEmbed } from "../../../../helper/discord";
|
||||
|
||||
export async function getOrSetDeviceId() {
|
||||
const store = await cookies();
|
||||
@@ -33,9 +34,44 @@ export const logAction = async (
|
||||
const headersList = await headers();
|
||||
const user = await getServerSession();
|
||||
|
||||
console.log("headers");
|
||||
const ip =
|
||||
headersList.get("X-Forwarded-For") ||
|
||||
headersList.get("Forwarded") ||
|
||||
headersList.get("X-Real-IP");
|
||||
|
||||
const deviceId = await getOrSetDeviceId();
|
||||
if (type == "LOGIN") {
|
||||
const existingLogs = await prisma.log.findMany({
|
||||
where: {
|
||||
type: "LOGIN",
|
||||
userId: {
|
||||
not: user?.user.id,
|
||||
},
|
||||
OR: [
|
||||
{
|
||||
ip: ip,
|
||||
},
|
||||
{
|
||||
deviceId: deviceId,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
if (existingLogs.length > 0 && user?.user.id) {
|
||||
// Möglicherweise ein doppelter Account, Report erstellen
|
||||
const report = await prisma.report.create({
|
||||
data: {
|
||||
text: `Möglicher doppelter Account erkannt bei Login-Versuch.\n\nÜbereinstimmende Logs:\n${existingLogs
|
||||
.map((log) => `- Log ID: ${log.id}, IP: ${log.ip}, Zeitstempel: ${log.timestamp}`)
|
||||
.join("\n")}`,
|
||||
reportedUserId: user?.user.id,
|
||||
reportedUserRole: "LOGIN - Doppelter Account Verdacht",
|
||||
},
|
||||
});
|
||||
|
||||
await sendReportEmbed(report.id);
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.log.create({
|
||||
data: {
|
||||
@@ -43,10 +79,7 @@ export const logAction = async (
|
||||
browser: headersList.get("user-agent") || "unknown",
|
||||
userId: user?.user.id,
|
||||
deviceId: deviceId,
|
||||
ip:
|
||||
headersList.get("X-Forwarded-For") ||
|
||||
headersList.get("Forwarded") ||
|
||||
headersList.get("X-Real-IP"),
|
||||
ip,
|
||||
...otherValues,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user