Files
portal/src/routes/(protected)/+layout.server.ts
T
NeilClack 4373458272 Allow profiles and license keys without a user; link them on registration
Admins can now create a Profile or License Key for someone who hasn't
registered yet (matched by email). When that person registers, any
unattached profile and license keys are linked to their new account.

Also remove the Proclamations surface from the user dashboard.
2026-08-27 12:04:09 -05:00

24 lines
718 B
TypeScript

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 };
};