Skip to content

Commit

Permalink
Redirect and delete cookie instead of 500ing
Browse files Browse the repository at this point in the history
  • Loading branch information
franknoirot committed Apr 4, 2024
1 parent 8360c91 commit 1f71c1e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1f71c1e

Please sign in to comment.