In this video we're going to take a look at a very easy way to capture the cookie that gets sent back
to us during this initial request and include that cookie in the follow up request right after it.
We're going to first take a look at this very easy way of handling this.
But then after that we're going to start to do a little bit larger refactor to make it really easy to
make authenticated requests in the future because again just about every other service we're going to
put together and write test for we're going to have to be authenticated to make requests to it.
So we want make sure that in a testing environment it is really really easy to get authenticated.
OK.
So here's the very easy solution.
We're going to first take a look at the initial request right here which should be giving us back a
cookie.
I'm going to capture the response so we get sent.
So I will call this something like off response maybe a better name for it would be like sign up response
or something like that.
So inside there is going to be the cookie that we actually care about so we can extract that thing using
response or off response that get set.
Cookie so we are pulling off that authentication cookie.
That is the thing that contains our Jason web token inside of it.
We now want to take that cookie and include it in this follow up request that we're making right here.
We can do so very easily by right after the dot get.
We're gonna add in another change on method of set.
We can use set to set different headers on the requests or about to make.
So in this case we're going to set the cookie better and we'll set it to the cookie that we got from
the initial auth response.
They'll put in cookie like so.
All right so let's now save this with back over to our terminal as are rerunning and there we go there
is our current user.
Now we could very easily write out a test and make sure that there is a current user property that is
defined and that there's some kind of e mail defined on there as well.
So for example I'm going to replace the console dot log right here but then expect response dot body
not current user dot email to equal.
And we'll have that email we'll make sure that it equals the email we had signed up as originally up
here.
That will say test at test dot com.
Let's say that you know flip back over and after these tests run again we should see now current user
is passing very good.
All right.
So it's headed out this approach right here works.
But as I mentioned every other service so we test are going to have to probably initially sign up somehow.
In other words we want to build to make authenticate requests to these other services very very easily
in a testing environment.
So going to take a quick pause right here.
When we come back the next video we're going to refactor some of this authentication stuff into a helper
function and his helper function.
We're going to eventually kind of copy paste around to a lot of different services.
It's going to make testing authentication and making sure we can make up their ticket requests really
easy and straightforward so quick pause and I'll see you in just a minute.