Update all routes to redirect users to create a profile if one does not exist
This commit is contained in:
@@ -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 };
|
||||
};
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user