Add team creation, team join and debug login screen

This commit is contained in:
2025-08-03 18:58:17 +02:00
parent facb07de5b
commit 36e8ef41bf
15 changed files with 735 additions and 11 deletions
+63
View File
@@ -0,0 +1,63 @@
import { useValidatedBody, useValidatedParams, z, zh } from 'h3-zod';
import prisma from '~~/lib/prisma';
import { randomBytes } from 'node:crypto';
export default defineEventHandler(async (event) => {
const { huntId } = await useValidatedParams(
event,
z.object({
huntId: zh.numAsString
})
);
const user = await requireUserSession(event);
const userId = user.user.id;
console.log(user);
const existingTeam = await prisma.huntTeam.findFirst({
select: {
id: true
},
where: {
huntId,
OR: [
{
ownerId: userId
},
{
members: {
some: {
memberId: userId
}
}
}
]
}
});
if (existingTeam) {
throw createError({ status: 409, statusText: 'You already have a team!' });
}
const { name, description } = await useValidatedBody(
event,
z.object({
name: z.string().max(256).min(3).trim(),
description: z.string().max(256).trim().optional()
})
);
const password = randomBytes(3).toString('hex');
const team = await prisma.huntTeam.create({
data: {
name,
description,
ownerId: userId,
password,
huntId
}
});
return { team };
});