diff --git a/frontend/src/app.tsx b/frontend/src/app.tsx index 07b3b2ab..8a22e6ee 100644 --- a/frontend/src/app.tsx +++ b/frontend/src/app.tsx @@ -13,6 +13,7 @@ import { useAuthData } from './utils/auth'; import { LoadingPage } from './pages/loading'; import { PagePage } from './pages/page'; import { AboutPage } from './pages/about'; +import { useGetConfig } from './api/config'; registerCopyHandler(); @@ -47,6 +48,26 @@ export function LoggedInRoute({ return ; } +export function LoggedInRedirectRoute({ + ...props +}: RouteProps) { + const [_, navigate] = useLocation(); + const { isLoggedIn, isLoading } = useAuthData(); + const { data: config, isLoading: configLoading } = useGetConfig({}); + if (isLoading) { + return ; + } + if (!isLoggedIn && !configLoading) { + if (config.logged_out_redirect_url) { + window.location.replace(config.logged_out_redirect_url); + } else { + navigate('/login'); + } + return null; + } + return ; +} + export function App() { const routerBase = trimTrailingSlash(import.meta.env.BASE_URL); @@ -59,7 +80,7 @@ export function App() { - +