From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Session provider wrapper

Session provider wrapper

All right. So in the last video, we created the AuthOptions object. We passed it into NextAuth, and we exported our handler in the route as GET and as POST. Now what we need to do is basically bring in the session provider and wrap our application. And we're going to do that in the layout. Now I don't want to bring the session provider directly into the layout and wrap it, because we do have to make it into a client component, and I don't want the layout to be a client component. So what we'll do is create the auth provider in a separate component, and then bring it into the layout, and then wrap it. So in components, let's create a new file called auth provider, and R-A-F-C-E, call it auth provider. And then here, we want to import the session provider. So that's going to be from, I believe it's next auth slash react. OK, then what we're going to want to do is this auth provider is going to take in children. So basically, whatever we pass in here, whatever we wrap is going to get…

Contents