From 1f71c1e28fbe4340ba47bd7e94405bb8544da8f2 Mon Sep 17 00:00:00 2001 From: Frank Noirot Date: Thu, 4 Apr 2024 11:04:57 -0400 Subject: [PATCH] Redirect and delete cookie instead of 500ing --- src/hooks.server.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 405457a..54e3e0c 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -1,4 +1,4 @@ -import { error, redirect } from '@sveltejs/kit' +import { redirect } from '@sveltejs/kit' import { AUTH_COOKIE_NAME } from '$lib/cookies' import { SIGN_OUT_PARAM } from '$lib/paths' import { PLAYWRIGHT_MOCKING_HEADER } from '$lib/consts' @@ -40,7 +40,11 @@ export const handle = async ({ event, resolve }) => { event.locals.user = undefined if (!unProtectedRoutes.includes(event.url.pathname)) throw redirect(303, '/') } else { - if ('error_code' in currentUser) throw error(500, currentUser) + if ('error_code' in currentUser) { + console.error('Error fetching user:', currentUser.error_code) + event.cookies.delete(AUTH_COOKIE_NAME, { domain, path: '/' }) + throw redirect(303, '/') + } event.locals.user = currentUser if (mock !== null) {