mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-12-06 05:24:11 +03:00
only redirect to login page once on 401
attempt to fix ios pwa safari redirect storm
This commit is contained in:
parent
87e67d22e2
commit
130dc76a01
@ -6,6 +6,10 @@ import { ReactNode } from "react";
|
|||||||
|
|
||||||
axios.defaults.baseURL = `${baseUrl}api/`;
|
axios.defaults.baseURL = `${baseUrl}api/`;
|
||||||
|
|
||||||
|
// Module-level flag to prevent multiple simultaneous redirects
|
||||||
|
// (eg, when multiple SWR queries fail with 401 at once)
|
||||||
|
let isRedirectingToLogin = false;
|
||||||
|
|
||||||
type ApiProviderType = {
|
type ApiProviderType = {
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
options?: Record<string, unknown>;
|
options?: Record<string, unknown>;
|
||||||
@ -31,7 +35,8 @@ export function ApiProvider({ children, options }: ApiProviderType) {
|
|||||||
) {
|
) {
|
||||||
// redirect to the login page if not already there
|
// redirect to the login page if not already there
|
||||||
const loginPage = error.response.headers.get("location") ?? "login";
|
const loginPage = error.response.headers.get("location") ?? "login";
|
||||||
if (window.location.href !== loginPage) {
|
if (window.location.href !== loginPage && !isRedirectingToLogin) {
|
||||||
|
isRedirectingToLogin = true;
|
||||||
window.location.href = loginPage;
|
window.location.href = loginPage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user