blogr-nextjs-prisma icon indicating copy to clipboard operation
blogr-nextjs-prisma copied to clipboard

Next-auth/client not found

Open pikooli opened this issue 3 years ago • 3 comments

I think Next-auth change the way it work.

https://github.com/nextauthjs/next-auth#add-react-hook

You have to replace the import with this :

  // import { useSession, signIn, signOut } from "next-auth/client"
  import { useSession, signOut } from "next-auth/react"

So you got the session with this :

  const { data : session, status } = useSession();

And you have to setup a session provider on the top component.

import { AppProps } from "next/app";
import { SessionProvider } from "next-auth/react"

const App = ({ Component, pageProps: { session, ...pageProps } }: AppProps) => {
  return (
    <SessionProvider session={session}>
      <Component {...pageProps} />
    </SessionProvider>
  );
};

export default App;

Tell me if i am wrong but it work for me

pikooli avatar Dec 17 '21 15:12 pikooli

I ran into this on windows as soon as Next-Auth was integrated

./components/Header.tsx:5:0 Module not found: Can't resolve 'next-auth/client' 3 | import Link from 'next/link'; 4 | import { useRouter } from 'next/router';

5 | import { signOut, useSession } from 'next-auth/client'; 6 | 7 | const Header: React.FC = () => { 8 | const router = useRouter();

S-Burns avatar Dec 25 '21 13:12 S-Burns

Hey man did you read what I post ? I said to import from

import { useSession, signOut } from "next-auth/react"

pikooli avatar Dec 25 '21 15:12 pikooli

You have to replace the import with this :

This all worked for me. Saw one more notice, need to update this line to be if (status) { now.

ian-pvd avatar Jan 24 '22 04:01 ian-pvd