Update all routes to redirect users to create a profile if one does not exist

This commit is contained in:
NeilClack
2026-02-24 08:17:37 -06:00
parent 3c201f9b66
commit b8d1ba11e7
5 changed files with 15 additions and 21 deletions
+5 -2
View File
@@ -1,15 +1,18 @@
import type { LayoutServerLoad } from './$types';
import { error } from '@sveltejs/kit';
import { error, redirect } from '@sveltejs/kit';
import { prisma } from '$lib/db';
export const load: LayoutServerLoad = async ({ locals }) => {
const user = await prisma.user.findUnique({
where: { id: locals.user?.id },
select: { id: true, roleId: true }
select: { id: true, roleId: true, profile: { select: { id: true } } }
});
if (!user) {
throw error(403, 'not authorized');
}
if (!user.profile) {
throw redirect(303, '/account/setup');
}
return { userRoleId: user.roleId };
};
+5 -14
View File
@@ -1,23 +1,14 @@
import type { PageServerLoad } from './$types';
import { prisma } from '$lib/db';
import { error, redirect } from '@sveltejs/kit';
import { error } from '@sveltejs/kit';
export const load: PageServerLoad = async ({ locals }) => {
const user = await prisma.user.findUnique({
where: {
id: locals.user?.id
},
include: {
profile: true
}
where: { id: locals.user?.id },
include: { profile: true }
});
if (user) {
if (!user?.profile) {
throw redirect(403, '/account/setup');
}
return { user };
} else {
if (!user) {
throw error(403, 'not authorized');
}
return { user };
};