prisma / blogr-nextjs-prisma

107 stars 82 forks source link

Next-auth/client not found #11

Open pikooli opened 2 years ago

pikooli commented 2 years ago

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
S-Burns commented 2 years ago

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();

pikooli commented 2 years ago

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

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

ian-pvd commented 2 years ago

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.