NextAuth (useSession) in app router.
Answered
Mark posted this in #help-forum
MarkOP
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.
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.
6 Replies
@Mark 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.
hi, you need to create a client component for the
SessionProvider // provider.tsx
'use client'
export default function AppProvider({children}) {
return <SessionProvider>{children}</SessionProvider>
}// layout.tsx
export default function RootLayout() {
return (
<html lang="en" suppressHydrationWarning>
<body>
<AppProvider>
{children}
</AppProvider>
</body>
</html>
)
}@Mark Hello,
This code is returning issues,
I am not entierly sure how to resolve them.
change the name to
provider.tsxAnswer
i had a typeo
MarkOP
ðŸ‘
Thanks, that resolved the problems.
Thanks, that resolved the problems.