Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions frontend/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading