Add requireAuth to AppShell

This commit is contained in:
David Corbitt
2023-08-08 13:20:02 -07:00
parent a2ace63f25
commit a2c322ff43
4 changed files with 24 additions and 71 deletions

View File

@@ -106,7 +106,15 @@ const NavSidebar = () => {
);
};
export default function AppShell(props: { children: React.ReactNode; title?: string }) {
export default function AppShell({
children,
title,
requireAuth,
}: {
children: React.ReactNode;
title?: string;
requireAuth?: boolean;
}) {
const [vh, setVh] = useState("100vh"); // Default height to prevent flicker on initial render
useEffect(() => {
@@ -126,14 +134,23 @@ export default function AppShell(props: { children: React.ReactNode; title?: str
};
}, []);
const user = useSession().data;
const authLoading = useSession().status === "loading";
useEffect(() => {
if (requireAuth && user === null && !authLoading) {
signIn("github").catch(console.error);
}
}, [requireAuth, user, authLoading]);
return (
<Flex h={vh} w="100vw">
<Head>
<title>{props.title ? `${props.title} | OpenPipe` : "OpenPipe"}</title>
<title>{title ? `${title} | OpenPipe` : "OpenPipe"}</title>
</Head>
<NavSidebar />
<Box h="100%" flex={1} overflowY="auto">
{props.children}
{children}
</Box>
</Flex>
);