diff --git a/packages/dashboard-v2/src/layouts/DashboardLayout.js b/packages/dashboard-v2/src/layouts/DashboardLayout.js index 32156549..07f4eabf 100644 --- a/packages/dashboard-v2/src/layouts/DashboardLayout.js +++ b/packages/dashboard-v2/src/layouts/DashboardLayout.js @@ -7,8 +7,9 @@ import { authenticatedOnly } from "../lib/swrConfig"; import { PageContainer } from "../components/PageContainer"; import { NavBar } from "../components/Navbar"; import { Footer } from "../components/Footer"; +import { UserProvider, useUser } from "../contexts/user"; -const Layout = styled.div.attrs({ +const Wrapper = styled.div.attrs({ className: "min-h-screen overflow-hidden", })` background-image: url(/images/dashboard-bg.svg); @@ -16,17 +17,35 @@ const Layout = styled.div.attrs({ background-repeat: no-repeat; `; +const Layout = ({ children }) => { + const { user } = useUser(); + + // Prevent from flashing the dashboard screen to unauthenticated users. + return ( + + {!user && ( + + Loading... {/* TODO: Do something nicer here */} + + )} + {user && <>{children}>} + + ); +}; + const DashboardLayout = ({ children }) => { return ( <> - - - - {children} - - - + + + + + {children} + + + + > ); diff --git a/packages/dashboard-v2/src/lib/swrConfig.js b/packages/dashboard-v2/src/lib/swrConfig.js index 66ccb44e..3e5f730a 100644 --- a/packages/dashboard-v2/src/lib/swrConfig.js +++ b/packages/dashboard-v2/src/lib/swrConfig.js @@ -8,6 +8,7 @@ const redirectUnauthenticated = (key) => fetch(`${baseUrl}/${key}`).then((response) => { if (response.status === StatusCodes.UNAUTHORIZED) { navigate(`/auth/login?return_to=${encodeURIComponent(window.location.href)}`); + return null; } return response.json();
Loading...