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:
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user