1

i add a load function in server side of sveltekit like this (+page.server.ts):

export const load: PageServerLoad = async ({ locals }) => {
    const { data, error } = await locals.sb.auth.getSession()
    if(data.session) {
        throw redirect(303, '/dashboard')
    } else {
        throw redirect(303,'/login')
    }
};

But get this errors:

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Redirect>".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

How can i fix this?

i have tried search but there is result using .catch() but i'm not sure how to use in svetekit?

Tymon tran
  • 11
  • 1

1 Answers1

-1

Use an empty try/catch, like this:

try {
    throw redirect(303, '/login')
} catch {       
}
Nicola Biada
  • 2,325
  • 1
  • 8
  • 22