课程: React: Creating and Hosting a Full-Stack Site

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Protecting endpoints using auth tokens

Protecting endpoints using auth tokens

- [Instructor] All right, so now that we've added firebase-admin to our express server, it's time to see how we can protect the upvote and comment endpoints so that only users who are logged in will be able to do those things. And additionally, we'll also see how to make sure that users are only allowed to add one upvote to an article. So what we're going to do here is use something called express middleware in order to check every request that comes in to see who's actually making that request, right? What user is actually doing that? So in order to do this, what we're going to do is after app.get, API article's name, right, we still want users who aren't authenticated to be able to access this so that they can see the comments and see the upvotes for the articles. After this, we're going to say app.use. And here's what this is going to look like. We're going to have an async callback function, right? We're going to say async function. And much like how we were able to say request…

内容