Fixes both the stuff pointed out by qudo

This commit is contained in:
Dum 2026-03-01 21:39:23 +05:30
parent ed08f2daab
commit 2e3de58a9c
2 changed files with 18 additions and 7 deletions

View file

@ -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,

View file

@ -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(),