Next.js Discord

Discord Forum

next-auth

Answered
Ghost ant posted this in #help-forum
Open in Discord
Ghost antOP
is there a special way or tutorial to use next-auth with the app directory? all i can seem to find is just the approaches with pages and app for using the use session provider, or it could be used in the general layout for app/?
Answered by Ghost ant
found this interesting and simple to follow tutorial for next-auth within the app directory for server and client side components in case some one founds it helpful 👍🏼 https://codevoweb.com/setup-and-use-nextauth-in-nextjs-13-app-directory/
View full answer

3 Replies

Yes, using it with the session provider is still fine. Server components can still use cilent providers, see the docs here: https://nextjs.org/docs/getting-started/react-essentials#rendering-third-party-context-providers-in-server-components
I think for me with NextAuth I also setup the middleware, which at that point allowed me to access the session on any Server Component using const session = await getServerSession(authOptions)

I'm not entirely sure if this was necessary to setup the middleware first or not, but I did start working for me after that.
Ghost antOP
found this interesting and simple to follow tutorial for next-auth within the app directory for server and client side components in case some one founds it helpful 👍🏼 https://codevoweb.com/setup-and-use-nextauth-in-nextjs-13-app-directory/
Answer