fix: prevent redirect loop on /account/setup for users without profile

- Skip profile redirect when already on /account/setup so users
  who just signed up/logged in land on the page without looping
- Add test for the skip-redirect case
This commit is contained in:
NeilClack
2026-07-07 09:14:14 -05:00
parent 209fd8456d
commit 5f1edc3174
2 changed files with 14 additions and 3 deletions
+3 -2
View File
@@ -2,7 +2,7 @@ import type { LayoutServerLoad } from './$types';
import { error, redirect } from '@sveltejs/kit';
import { prisma } from '$lib/db';
export const load: LayoutServerLoad = async ({ locals }) => {
export const load: LayoutServerLoad = async ({ locals, url }) => {
if (!locals.user?.id) {
throw error(403, 'not authorized');
}
@@ -14,7 +14,8 @@ export const load: LayoutServerLoad = async ({ locals }) => {
if (!user) {
throw error(403, 'not authorized');
}
if (!user.profile) {
if (!user.profile && !url.pathname.startsWith('/account/setup')) {
// Skip redirect when already on /account/setup to avoid redirect loop
throw redirect(303, '/account/setup');
}