import { error } from '@sveltejs/kit'; import type { PageServerLoad } from './$types.js'; import { prisma } from '$lib/server/db.js'; export const load: PageServerLoad = async ({ params, locals }) => { const invite = await prisma.tenantInvite.findUnique({ where: { code: params.code }, include: { tenant: { select: { name: true } } } }); if (!invite) throw error(404, 'Invite not found'); if (invite.expiresAt < new Date()) { throw error(410, 'This invite has expired'); } if (invite.maxUses !== null && invite.usedCount >= invite.maxUses) { throw error(410, 'This invite has reached its maximum number of uses'); } return { invite: { code: invite.code, role: invite.role, tenantName: invite.tenant.name, expiresAt: invite.expiresAt.toISOString() }, user: locals.user }; };