Next.js Discord

Discord Forum

NextAuth (useSession) in app router.

Answered
Mark posted this in #help-forum
Open in Discord
Greetings.
I am working on a small ish project where i want people to be able to log into the project and add something to a "board of ideas" and later expand on it, currently i have nextauth basics in order with custom Credentials provider (user, password & database) however i am having an issue with making sure that the user is authenticated on specific pages.
I cannot use "useSession" as my project is not wrapped in SessionProvider and if i do wrap it i get an issue that it cannot be used in server components...
So i am kinda just lost.
Any help would be appreciated.
Answered by Ray
change the name to provider.tsx
View full answer

6 Replies

// layout.tsx

export default function RootLayout() {
  return (
     <html lang="en" suppressHydrationWarning>
      <body>
        <AppProvider>
          {children}
        </AppProvider>
      </body>
    </html>
  )
}
@Ray hi, you need to create a client component for the `SessionProvider` ts // provider.tsx 'use client' export default function AppProvider({children}) { return <SessionProvider>{children}</SessionProvider> }
Hello,
This code is returning issues,
I am not entierly sure how to resolve them.
Answer
i had a typeo
👍
Thanks, that resolved the problems.