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.
Sign-out and protect routes - Next.js Tutorial
From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
Sign-out and protect routes
So our authentication system is almost complete. We need to be able to sign out now, which is going to be really simple. We basically just need to call a function. And then I also want to be able to protect routes. Like if we're not logged in, we shouldn't be able to go to add property. So we'll probably do that in this video as well. So let's go to the nav bar, because that's where all this authentication stuff is happening. And we're already bringing in sign out. So basically, we just need to call that. So let's go. I'm just going to search for out, or not out. Let's say sign space out. Yeah, and there's only one because this shows on both mobile and desktop. So we just want to go to this button and then do an on click. And we're going to have a function. And two things I want to do. One, I want to set the isProfileMenuOpen. We want to set that to false, because we want that to go away once we sign out. So let's say set isProfileMenuOpen to false. Then we want to call sign out. And…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.