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
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
-
-
-
-
-
-
-
Why Firebase Auth?1m 17s
-
(Locked)
Creating a Firebase project4m 16s
-
(Locked)
Adding Firebase Auth to React9m 27s
-
(Locked)
Build a login form11m 56s
-
(Locked)
Creating a custom auth hook8m 52s
-
(Locked)
Build a create-account page7m 59s
-
(Locked)
Adding Firebase Auth to Node.js6m 25s
-
(Locked)
Protecting endpoints using auth-tokens8m 44s
-
(Locked)
Protecting the upvote and comment endpoints4m 47s
-
(Locked)
Making requests with auth tokens6m 41s
-
(Locked)
Making interface adjustments for authenticated users6m 34s
-
-
-