From 9f1e2c9ff52c3c86a0cd566c9cb668de476d327c Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 17 May 2026 22:45:46 +0200 Subject: [PATCH] refactor(auth): hooks.server.ts re-throws redirects via isRedirect() Replace the duck-typed `status in error && location in error` check with the official SvelteKit guard. Fragile against minor-version error-shape changes becomes a one-liner against a typed helper. Addresses PR #612 / Felix F1. Co-Authored-By: Claude Opus 4.7 --- frontend/src/hooks.server.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frontend/src/hooks.server.ts b/frontend/src/hooks.server.ts index 5fe167c1..de71e2b9 100644 --- a/frontend/src/hooks.server.ts +++ b/frontend/src/hooks.server.ts @@ -1,5 +1,5 @@ import * as Sentry from '@sentry/sveltekit'; -import { redirect, type Handle, type HandleFetch } from '@sveltejs/kit'; +import { isRedirect, redirect, type Handle, type HandleFetch } from '@sveltejs/kit'; import { paraglideMiddleware } from '$lib/paraglide/server'; import { sequence } from '@sveltejs/kit/hooks'; import { env } from 'process'; @@ -87,10 +87,9 @@ const userGroup: Handle = async ({ event, resolve }) => { } } } catch (error) { - // Don't swallow SvelteKit redirects — they're thrown as objects with a `status` field. - if (error instanceof Object && 'status' in error && 'location' in error) { - throw error; - } + // Re-throw SvelteKit redirects (e.g. the /login?reason=expired throw above) + // using the official guard rather than duck-typing on the error shape. + if (isRedirect(error)) throw error; console.error('Error fetching user in hook:', error); }