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.

Get user and submit to database

Get user and submit to database

OK, so now we need to get the user when they submit a new property because we need to include them as the owner. So to get the user, we need to get the session, but we need to get it in this file, in this route.js. So what I'm going to do is create a separate file. Actually, you know what? Let's put it here first, and then we'll change it up, and I'll show you how we can move it to a new file, because we will need to do this in many other routes to get the user. So we'll have a separate utility file that will get the user from the session. So first thing we're going to do is import the, let's say, get. So it's not get session, it's a get server session. So it's a bit different, and it works a bit different than it does with get session, or sorry, use session in the front end. And that's going to be from next auth slash next. And then remember I told you we put the provider stuff in this auth options file. We put it here instead of directly in the next auth route because we need to use…

Contents