I'm using NextAuth on a NextJs project and I'm getting the error "Type error: Property 'session' does not exist on type '{}'."
. I'm adding the session
property to my _app.tsx as suggested here:
https://next-auth.js.org/getting-started/example
I've also added that property to my custom MyApp
type interface but I still get the error. Follow my code:
import { NextComponentType } from "next";
import { Session } from "next-auth";
export interface CustomAppProps extends AppProps {
Component: NextComponentType & { auth?: boolean; session?: Session };
}
function MyApp({ Component, pageProps: { session, ...pageProps } }: CustomAppProps) {
//...
});
How can I fix it? Thanks!
Edit #1 (adding MyApp
with my current code):
function MyApp({ Component, pageProps: { session, ...pageProps } }: CustomAppProps) {
return (
<>
<CookieConsentProvider useCookieConsentHooksOptions={{ consentCookieAttributes: { expires: 360 } }}>
<SessionProvider session={session}>
<AppContextProvider>
<Component {...pageProps} />
</AppContextProvider>
</SessionProvider>
</CookieConsentProvider>
</>
);
}
Edit #2:
function MyApp({ Component, pageProps }: AppProps) {
return (
<>
<CookieConsentProvider useCookieConsentHooksOptions={{ consentCookieAttributes: { expires: 360 } }}>
<SessionProvider session={pageProps.session}>
<AppContextProvider>
<Component {...pageProps} />
</AppContextProvider>
</SessionProvider>
</CookieConsentProvider>
</>
);
}
Using the code above I still get the TS error: