Home > Software design >  (NextAuth) Type error: Property 'session' does not exist on type '{}'
(NextAuth) Type error: Property 'session' does not exist on type '{}'

Time:09-10

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:

enter image description here

CodePudding user response:

Either your type definition is wrong, or your prop destructuring is wrong.

This type definition matches your destructuring:

export interface CustomAppProps extends AppProps {
  Component: NextComponentType;
  pageProps: { auth?: boolean; session?: Session }
}

CodePudding user response:

I managed to fix that error by adding a custom type file to my project, as I saw on NexthAuth.js Github repository:

https://github.com/nextauthjs/next-auth-typescript-example/blob/main/types/next.d.ts

Just copied that to my project and that works now. Not sure why it used to work as I never had it before.

  • Related