useSession must be wrapped in a <SessionProvider />

pages/_app.tsx
// pages/_app.tsx
export type NextPageWithLayout = NextPage & {
getLayout?: (page: ReactElement) => ReactNode;
};

type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout;
};

const DoeApp: AppType<{ session: Session | null }> = ({
Component,
pageProps: { session, ...pageProps },
}: AppPropsWithLayout) => {
const getLayout = Component.getLayout ?? ((page) => page);
const layout = getLayout(<Component {...pageProps} />);

return (
<SessionProvider session={session}>
{layout}
</SessionProvider>
);
};

export default trpc.withTRPC(DoeApp);
// pages/_app.tsx
export type NextPageWithLayout = NextPage & {
getLayout?: (page: ReactElement) => ReactNode;
};

type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout;
};

const DoeApp: AppType<{ session: Session | null }> = ({
Component,
pageProps: { session, ...pageProps },
}: AppPropsWithLayout) => {
const getLayout = Component.getLayout ?? ((page) => page);
const layout = getLayout(<Component {...pageProps} />);

return (
<SessionProvider session={session}>
{layout}
</SessionProvider>
);
};

export default trpc.withTRPC(DoeApp);
pages/terms-of-service.tsx
const TermsOfService: NextPageWithLayout = () => {
return <div>
<div>Terms of service</div>
</div>
}

TermsOfService.getLayout = (page) => {
const session = useSession();
if (session.data) {
return <Layout>{page}</Layout>;
}
return <div className="min-h-screen dark:bg-black text-white">{page}</div>
}

export default TermsOfService;
const TermsOfService: NextPageWithLayout = () => {
return <div>
<div>Terms of service</div>
</div>
}

TermsOfService.getLayout = (page) => {
const session = useSession();
if (session.data) {
return <Layout>{page}</Layout>;
}
return <div className="min-h-screen dark:bg-black text-white">{page}</div>
}

export default TermsOfService;
11 Replies
mid
mid2y ago
@create-t3-maintainer @Theo-Ish @Moderator
devagr
devagr2y ago
what
Mir
Mir2y ago
bruh
mid
mid2y ago
I've a;sp tried const layout = getLayout(<Component {...pageProps} />);
cje
cje2y ago
Don’t do this
christian
christian2y ago
Yeah don’t It’s 1am my time Be considerate
devagr
devagr2y ago
be considerate of not being kicked
theo (t3.gg)
theo (t3.gg)2y ago
Fuck this I'm permaing him
devagr
devagr2y ago
bruh don't make him go to everyone's DMs
julius
julius2y ago
bruh
Aiden
Aiden2y ago
Have you tried rewriting it in rust
Want results from more Discord servers?
Add your server