From 7848c906251164d20f7035aec30a58bcf44d854e Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Wed, 11 Mar 2026 23:35:27 +0100 Subject: [PATCH] feat: add error handling for sessionStorage in redirect logic across multiple pages --- app/[locale]/auth/callback/page.tsx | 2 +- app/[locale]/calendar/page.tsx | 2 +- app/[locale]/contacts/page.tsx | 2 +- app/[locale]/login/page.tsx | 6 +++--- app/[locale]/page.tsx | 2 +- app/[locale]/settings/page.tsx | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/[locale]/auth/callback/page.tsx b/app/[locale]/auth/callback/page.tsx index b0f52bc9..e9f1b8da 100644 --- a/app/[locale]/auth/callback/page.tsx +++ b/app/[locale]/auth/callback/page.tsx @@ -60,7 +60,7 @@ function OAuthCallbackInner() { sessionStorage.removeItem('redirect_after_login'); redirectTo = saved; } - } catch {} + } catch { /* sessionStorage may be unavailable */ } router.push(redirectTo); } else { setError("token_exchange_failed"); diff --git a/app/[locale]/calendar/page.tsx b/app/[locale]/calendar/page.tsx index d6b81270..e3b98941 100644 --- a/app/[locale]/calendar/page.tsx +++ b/app/[locale]/calendar/page.tsx @@ -77,7 +77,7 @@ export default function CalendarPage() { useEffect(() => { if (!isAuthenticated) { - try { sessionStorage.setItem('redirect_after_login', window.location.pathname); } catch {} + try { sessionStorage.setItem('redirect_after_login', window.location.pathname); } catch { /* ignore */ } router.push("/login"); } else if (!supportsCalendar) { router.push("/"); diff --git a/app/[locale]/contacts/page.tsx b/app/[locale]/contacts/page.tsx index f5c41ea3..a29c0fcc 100644 --- a/app/[locale]/contacts/page.tsx +++ b/app/[locale]/contacts/page.tsx @@ -79,7 +79,7 @@ export default function ContactsPage() { useEffect(() => { if (!isAuthenticated) { - try { sessionStorage.setItem('redirect_after_login', window.location.pathname); } catch {} + try { sessionStorage.setItem('redirect_after_login', window.location.pathname); } catch { /* ignore */ } router.push("/login"); } }, [isAuthenticated, router]); diff --git a/app/[locale]/login/page.tsx b/app/[locale]/login/page.tsx index 4d4a36c0..158a71f7 100644 --- a/app/[locale]/login/page.tsx +++ b/app/[locale]/login/page.tsx @@ -100,7 +100,7 @@ export default function LoginPage() { sessionStorage.removeItem('redirect_after_login'); redirectTo = saved; } - } catch {} + } catch { /* ignore */ } router.push(redirectTo); } }, [isAuthenticated, router]); @@ -314,7 +314,7 @@ export default function LoginPage() { sessionStorage.removeItem('redirect_after_login'); redirectTo = saved; } - } catch {} + } catch { /* ignore */ } router.push(redirectTo); } }; @@ -329,7 +329,7 @@ export default function LoginPage() { sessionStorage.removeItem('redirect_after_login'); redirectTo = saved; } - } catch {} + } catch { /* ignore */ } router.push(redirectTo); } }; diff --git a/app/[locale]/page.tsx b/app/[locale]/page.tsx index 5e79537b..c3c8aadf 100644 --- a/app/[locale]/page.tsx +++ b/app/[locale]/page.tsx @@ -264,7 +264,7 @@ export default function Home() { // Redirect to login if not authenticated useEffect(() => { if (initialCheckDone && !isAuthenticated && !authLoading) { - try { sessionStorage.setItem('redirect_after_login', window.location.pathname); } catch {} + try { sessionStorage.setItem('redirect_after_login', window.location.pathname); } catch { /* ignore */ } router.push('/login'); } }, [initialCheckDone, isAuthenticated, authLoading, router]); diff --git a/app/[locale]/settings/page.tsx b/app/[locale]/settings/page.tsx index c4dc8639..9af0b7b0 100644 --- a/app/[locale]/settings/page.tsx +++ b/app/[locale]/settings/page.tsx @@ -35,7 +35,7 @@ export default function SettingsPage() { useEffect(() => { if (!isAuthenticated) { - try { sessionStorage.setItem('redirect_after_login', window.location.pathname); } catch {} + try { sessionStorage.setItem('redirect_after_login', window.location.pathname); } catch { /* ignore */ } router.push('/login'); } }, [isAuthenticated, router]);