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 type { LayoutServerLoad } from './$types';
import { error } from '@sveltejs/kit'; import { error, redirect } from '@sveltejs/kit';
import { prisma } from '$lib/db'; import { prisma } from '$lib/db';
export const load: LayoutServerLoad = async ({ locals }) => { export const load: LayoutServerLoad = async ({ locals }) => {
const user = await prisma.user.findUnique({ const user = await prisma.user.findUnique({
where: { id: locals.user?.id }, where: { id: locals.user?.id },
select: { id: true, roleId: true } select: { id: true, roleId: true, profile: { select: { id: true } } }
}); });
if (!user) { if (!user) {
throw error(403, 'not authorized'); throw error(403, 'not authorized');
} }
if (!user.profile) {
throw redirect(303, '/account/setup');
}
return { userRoleId: user.roleId }; return { userRoleId: user.roleId };
}; };
+5 -14
View File
@@ -1,23 +1,14 @@
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
import { prisma } from '$lib/db'; import { prisma } from '$lib/db';
import { error, redirect } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
export const load: PageServerLoad = async ({ locals }) => { export const load: PageServerLoad = async ({ locals }) => {
const user = await prisma.user.findUnique({ const user = await prisma.user.findUnique({
where: { where: { id: locals.user?.id },
id: locals.user?.id include: { profile: true }
},
include: {
profile: true
}
}); });
if (!user) {
if (user) {
if (!user?.profile) {
throw redirect(403, '/account/setup');
}
return { user };
} else {
throw error(403, 'not authorized'); throw error(403, 'not authorized');
} }
return { user };
}; };
+2 -2
View File
@@ -18,7 +18,7 @@
return; return;
} }
window.location.href = '/'; window.location.href = '/account';
} }
</script> </script>
@@ -41,7 +41,7 @@
<button <button
onclick={async () => { onclick={async () => {
console.log('signing in with google'); console.log('signing in with google');
authClient.signIn.social({ provider: 'google' }); authClient.signIn.social({ provider: 'google', callbackURL: '/account' });
}} }}
> >
<img src="light/web_light_sq_SI.svg" alt="Sign In with Google" /> <img src="light/web_light_sq_SI.svg" alt="Sign In with Google" />
+2 -2
View File
@@ -1,6 +1,6 @@
import type { Actions } from "./$types"; import type { Actions } from "./$types";
import { auth } from "$lib/auth"; import { auth } from "$lib/auth";
import { fail } from "@sveltejs/kit"; import { fail, redirect } from "@sveltejs/kit";
export const actions: Actions = { export const actions: Actions = {
default: async ({ request }) => { default: async ({ request }) => {
@@ -26,7 +26,7 @@ export const actions: Actions = {
}) })
if (response.user) { if (response.user) {
return { success: true } throw redirect(303, '/account/setup');
} }
} catch (err) { } catch (err) {
return fail(400, err); return fail(400, err);
+1 -1
View File
@@ -19,7 +19,7 @@
<button <button
class="mx-auto" class="mx-auto"
on:click={async () => { on:click={async () => {
authClient.signIn.social({ provider: 'google' }); authClient.signIn.social({ provider: 'google', callbackURL: '/account/setup' });
}}><img src="light/web_light_sq_SU.svg" alt="Sign Up with Google" /></button }}><img src="light/web_light_sq_SU.svg" alt="Sign Up with Google" /></button
> >
</div> </div>