From 8bd23777828601bfb5e151fa091a3ff5ab8a26d1 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 9 Jun 2026 17:33:35 -0300 Subject: [PATCH] change browsers fetch to get 401s and redirect --- frontend/app/providers.tsx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/frontend/app/providers.tsx b/frontend/app/providers.tsx index 7a765fd04..f593a5b4f 100644 --- a/frontend/app/providers.tsx +++ b/frontend/app/providers.tsx @@ -3,6 +3,32 @@ import { QueryClientProvider } from "@tanstack/react-query"; import type * as React from "react"; import { getQueryClient } from "@/app/api/get-query-client"; +if (typeof window !== "undefined") { + const originalFetch = window.fetch; + window.fetch = async (...args) => { + const response = await originalFetch(...args); + if (response.status === 401) { + try { + const clone = response.clone(); + const data = await clone.json(); + if (data && typeof data === "object") { + const redirectUrl = + data.redirect_url || data.redirectUrl || data.redirect; + if (redirectUrl && typeof redirectUrl === "string") { + window.location.href = redirectUrl; + } + } + } catch (e) { + console.error( + "Failed to parse 401 response payload for redirect url:", + e, + ); + } + } + return response; + }; +} + export default function Providers({ children }: { children: React.ReactNode }) { const queryClient = getQueryClient();