import type { LayoutServerLoad } from './$types'; import { error, redirect } from '@sveltejs/kit'; import { prisma } from '$lib/db'; export const load: LayoutServerLoad = async ({ locals, url }) => { if (!locals.user?.id) { throw error(403, 'not authorized'); } const user = await prisma.user.findUnique({ where: { id: locals.user.id }, select: { id: true, roleId: true, profiles: { select: { id: true } } } }); if (!user) { throw error(403, 'not authorized'); } if (user.profiles.length === 0 && !url.pathname.startsWith('/account/setup')) { // Skip redirect when already on /account/setup to avoid redirect loop throw redirect(303, '/account/setup'); } return { userRoleId: user.roleId }; };