Help with layout
Answered
Giant panda posted this in #help-forum
Giant pandaOP
I am using supabase auth nexjs project, in my app/layout.tsx i have a header component but when i log in the middleware makes the protected endpoint, the root endpoint but on my protected page i dont want this header to show, how would i do this?
Answered by B33fb0n3
You can create two route groups (unprotected and protected). Inside one route group you have your header and in the other not
14 Replies
Giant pandaOP
this is my app/layout.tsx
ignore sidebar stuff and my protected endpoint has no layout.tsx
export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const cookieStore = await cookies()
const defaultOpen = cookieStore.get("sidebar:state")?.value === "true"
return (
<html lang="en" className={GeistSans.className} suppressHydrationWarning>
<body>
<ThemeProvider
attribute="class"
defaultTheme="system"
enableSystem
disableTransitionOnChange
>
{/*<SidebarProvider defaultOpen={defaultOpen}>*/}
{/* <AppSidebar/>*/}
<main className="h-screen flex flex-col">
<Header />
<div className="flex-1 overflow-y-auto">
{children}
</div>
</main>
{/*</SidebarProvider>*/}
</ThemeProvider>
</body>
</html>
);
}
ignore sidebar stuff and my protected endpoint has no layout.tsx
West African Crocodile
oh, I am sorry, I don't understand your problem so well.
you mean, you wanna don't show your sidebar in protected pages?
you mean, you wanna don't show your sidebar in protected pages?
Giant pandaOP
my header
not sidebar
yes i dont want to show my header on protected pages
@Giant panda yes i dont want to show my header on protected pages
You can create two route groups (unprotected and protected). Inside one route group you have your header and in the other not
Answer
Giant pandaOP
ok thanks, ill see how to do this
Happy to help
Giant pandaOP
@B33fb0n3 not sure how to get this working, is there a resource you would recommend to for this?
because of the middleware with supabase, where going to / takes you to /protected once authenticated
@Giant panda <@301376057326567425> not sure how to get this working, is there a resource you would recommend to for this?
Yea, you can use this one: https://nextjs.org/docs/app/building-your-application/routing/route-groups
if you have a middleware or not shouldn’t matter
if you have a middleware or not shouldn’t matter
Giant pandaOP
Yh I’ve got it working
Thanks tho