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

免费学习该课程!

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

Making requests with auth tokens

Making requests with auth tokens

- [Instructor] Well now that we've protected our endpoints and there are actually a few adjustments that we'll need to make to this code before it will work properly, but we'll get to those a little bit later. The next thing that we're going to do is we need our front end to actually send along this authtoken when it makes a request to one of these endpoints. So what we're going to do here is we're going to open up our ArticlePage, and this has functionality for both upvoting and adding a comment. So inside here, we just need to have access to the user that's currently logged in and send that user's authtoken along with whatever requests we make. So here's what this is going to look like. We're going to say import useUser from, and then we're going to say dot dot slash useUser. And now that we have that, we're going to add that hook to this article page component by saying, const user. Well here, we'll need isLoading first of all, and then user equals useUser. So now we have access to…

内容