From b94320aa441cbbd31dd8ede40b84c2e7df600313 Mon Sep 17 00:00:00 2001 From: UltraLionFr Date: Tue, 29 Jul 2025 06:11:21 +0200 Subject: [PATCH] Update updateMinecraftName --- app/dashboard/actions.ts | 31 ++++++++++++++++++++++--------- app/dashboard/profil/page.tsx | 6 ++++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/app/dashboard/actions.ts b/app/dashboard/actions.ts index 5ab2590..e37ef5f 100644 --- a/app/dashboard/actions.ts +++ b/app/dashboard/actions.ts @@ -74,17 +74,30 @@ export async function updateMinecraftName(form: FormData) { const mcName = (form.get("mcName") as string).trim(); if (!/^[A-Za-z0-9_]{3,16}$/.test(mcName)) throw new Error("invalid"); - await prisma.user.upsert({ + const user = await prisma.user.findUnique({ where: { email: session.user!.email! }, - update: { mcName }, - create: { - email: session.user!.email!, - name: session.user!.name, - image: session.user!.image, - mcName, - }, }); + if (!user) { + await prisma.user.create({ + data: { + email: session.user!.email!, + name: session.user!.name, + image: session.user!.image, + mcName, + }, + }); + } else { + if (user.mcName) { + throw new Error("Le pseudo Minecraft ne peut pas être modifié après avoir été défini."); + } + + await prisma.user.update({ + where: { email: session.user!.email! }, + data: { mcName }, + }); + } + revalidatePath("/dashboard"); revalidatePath("/"); -} \ No newline at end of file +} diff --git a/app/dashboard/profil/page.tsx b/app/dashboard/profil/page.tsx index 59747d9..5d34bb3 100644 --- a/app/dashboard/profil/page.tsx +++ b/app/dashboard/profil/page.tsx @@ -60,13 +60,15 @@ export default async function ProfilPage() { placeholder="Pseudo MC" required pattern="[A-Za-z0-9_]{3,16}" - className="input pl-12" + disabled={Boolean(user?.mcName)} + className="input pl-12 disabled:opacity-60" />