From the course: React: Creating and Hosting a Full-Stack Site

Schalten Sie den kompletten Kurs noch heute frei

Join today to access over 23,400 courses taught by industry experts.

Protecting the upvote and comment endpoints

Protecting the upvote and comment endpoints

From the course: React: Creating and Hosting a Full-Stack Site

Protecting the upvote and comment endpoints

"

- [Instructor] The next two endpoints are going to be a little bit trickier, I believe. So, first of all, let's take a look at how to refactor this up vote endpoint so that we make sure that only users who haven't up-voted the article before can do so. Well, first of all, one thing that we should notice is that the up vote endpoint and the comments endpoint are both going to have the same initial criteria. And that is, if the user isn't already logged in we don't want the user to be able to make requests to either of these endpoints. So, what we can actually do is add another piece of middleware right above these two routes that will only apply to these two routes. And that's going to look like this. We're just going to say app dot use. And then we're going to say request response and next. And for the body of this we're going to say, if request dot user, right? In other words, if the user exists and has included the…

Inhalt