How to add auth property to NextComponentType

Hey, I want to add auth flag to next components to check if page should be protected. I tried extending its interface but without any success.
declare module "next" {
interface NextComponentType {
auth: boolean;
}
}
declare module "next" {
interface NextComponentType {
auth: boolean;
}
}
Here is my _app code
const MyApp: AppType<{ session: Session | null }> = ({
Component,
pageProps: { session, ...pageProps },
}) => {
return (
<SessionProvider session={session}>
{Component.auth ? (
<Auth>
<Layout>
<Component {...pageProps} />
</Layout>
</Auth>
) : (
<Component {...pageProps} />
)}
</SessionProvider>
);
};
const MyApp: AppType<{ session: Session | null }> = ({
Component,
pageProps: { session, ...pageProps },
}) => {
return (
<SessionProvider session={session}>
{Component.auth ? (
<Auth>
<Layout>
<Component {...pageProps} />
</Layout>
</Auth>
) : (
<Component {...pageProps} />
)}
</SessionProvider>
);
};
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server