Fixed Acc deleted Warnung im Profil

This commit is contained in:
PxlLoewe
2026-02-07 13:43:37 +01:00
parent 2e9bb95d12
commit 8340c2408c
3 changed files with 20 additions and 23 deletions

View File

@@ -1,6 +1,6 @@
import axios from "axios";
import { NextRequest, NextResponse } from "next/server";
import { DiscordAccount, prisma } from "@repo/db";
import { prisma } from "@repo/db";
import { getServerSession } from "../auth/[...nextauth]/auth";
import { setStandardName } from "../../../helper/discord";
import { getUserPenaltys } from "@repo/shared-components";
@@ -52,8 +52,7 @@ export const GET = async (req: NextRequest) => {
},
});
const discordObject = {
userId: session.user.id,
const discordData = {
accessToken: authData.access_token,
refreshToken: authData.refresh_token,
discordId: discordUser.id,
@@ -63,12 +62,19 @@ export const GET = async (req: NextRequest) => {
globalName: discordUser.global_name || discordUser.username,
verified: discordUser.verified,
tokenType: authData.token_type,
} as DiscordAccount;
};
await prisma.discordAccount.upsert({
where: { discordId: discordUser.id },
update: discordObject, // Updates if found
create: discordObject, // Creates if not found
update: discordData, // Updates if found
create: {
...discordData,
User: {
connect: {
id: session.user.id,
},
},
}, // Creates if not found
});
const user = await prisma.user.findUnique({
where: { id: session.user.id },