From 2e3de58a9ccc60cd9ea20e60c2c6dee8928a18b0 Mon Sep 17 00:00:00 2001 From: Dum Date: Sun, 1 Mar 2026 21:39:23 +0530 Subject: [PATCH] Fixes both the stuff pointed out by qudo --- server/routes/sessions/[sid]/index.ts | 23 +++++++++++++++++------ server/utils/auth.ts | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/server/routes/sessions/[sid]/index.ts b/server/routes/sessions/[sid]/index.ts index 4ecddaa..fb9e527 100644 --- a/server/routes/sessions/[sid]/index.ts +++ b/server/routes/sessions/[sid]/index.ts @@ -40,12 +40,23 @@ export default defineEventHandler(async event => { const validatedBody = updateSessionSchema.parse(body); // Use update return value directly — no redundant findUnique - const updatedSession = validatedBody.deviceName - ? await prisma.sessions.update({ - where: { id: sessionId }, - data: { device: validatedBody.deviceName }, - }) - : targetedSession; + let updatedSession; + try { + updatedSession = validatedBody.deviceName + ? await prisma.sessions.update({ + where: { id: sessionId }, + data: { device: validatedBody.deviceName }, + }) + : targetedSession; + } catch (err: any) { + if (err.code === 'P2002') { + throw createError({ + statusCode: 409, + message: 'A session with this device name already exists', + }); + } + throw err; + } return { id: updatedSession.id, diff --git a/server/utils/auth.ts b/server/utils/auth.ts index 0025d39..696ea48 100644 --- a/server/utils/auth.ts +++ b/server/utils/auth.ts @@ -43,7 +43,7 @@ export function useAuth() { // Atomic upsert — backed by @@unique([user, device]) in schema return await prisma.sessions.upsert({ where: { - sessions_user_device_unique: { user, device }, + user_device: { user, device }, }, update: { id: uuidv7(),