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.

Making requests with auth tokens

Making requests with auth tokens

"

- Okay. So now that we've added route protection to all of the routes on our server, the last thing that we're going to need to do is actually add the auth token that we're referring to in our middleware here, to all of the requests that we make from our article page, right? And this will be how our client proves that the user is logged in to our server. So what we're going to do is open up our article page and basically everywhere that we make a request using axios, we're going to have to include a header with the users auth token. Now, the good news is that since we've created this 'useUser' custom hook and have access to the user directly it's going to be pretty straightforward to do this. So to start off, let's change our load article info request so that it includes the header. This will be a good way to kind of get our feet wet with this. So first things first in order to get the user's auth token from this user…

Inhalt