As we just saw, we are double fetching the current user between the landing page and the app component.
So we can fix that up really quickly inside this video to get started.
I'm going to go backwards, my index dot, G.S. file.
We're going to find the get initial props function.
I'm going to delete everything that we have inside there for right now.
Instead, I'm going to return an empty object.
I'm also going to delete the Bild client statement at the very top, because we are not importing that.
We're not making any use of with that build client function right now.
Now, if I go back over to my application after saving that file and refresh the page, you might see
it that you are now no longer signed in.
Even if you actually are signed in.
So if I click on the logo right there, again, that's going to reissue the current user request.
And if I look at the response, I can see very plainly that I am, in fact, signed into the application.
But the outcome or the landing page component definitely thinks that I'm not.
The reason for that is that the landing page is not receiving the current user as a prop.
So we need to go back over to our app component, which is still fetching the current user.
So when the app component renders itself with the current user, we need to make sure that we take that
current user and pass it down as a property down into the child component.
This is going to make sure that every single child component inside of our application.
So essentially every component side, the pages directory will always receive the current user as a
prop, which is probably a very good thing.
There's probably gonna be many scenarios, many different pages that we're going to create that need
to understand who the current user is.
But this is going to be a nice little thing that's going to help us easily understand who the current
user is and all the different pages in the future.
So on our component right there, we'll add in a prop of current user.
And assigned to it.
Burnt user.
Now, I can flip back over if I refresh the page.
I will once again see that I am signed in.
And if I click on the Get Ticks logo yet again, I'll see that I'm now only making one request to fetch
the current user.
OK.
Very good.
That's one little fix, but there's one other fix that I would like to make as well.
Inside of our app components, we are importing that build client helper.
Now, as a reminder on what that build client thing is, we can go to our API directory inside the client
folder and find the build client file.
Remember, depending upon whether we are running our application or really rendering our app on the
Cuban Nettie's cluster.
So during the server side rendering phase, or whether we are running our app inside the browser, we
are creating a slightly different copy of Axios.
So every single time we fetch data, we need to first run this build client function.
In other words, for every get initial props, we need to somehow get the current client.
Rarely connected either to Ingress and Genex or to, well, just use the base, you are all in other
words, just use the current domain, make a request back off to our endpoint or our back and servers.
Now, as we just saw inside the index, such as File, we had the build client impressed him at the
very top and then we were just a moment ago reading client inside of get initial props.
That would be a really tedious to repeat for every single page component inside of our app.
In other words, would be just a little bit of a pain every single time to have to import, build a
client and then build up client inside to get initial props.
So we're gonna fix that up here.
We're gonna make it a little bit easier to fetch some data very easily without having to first import
that build client helper.
Back inside of our app component, you might recall that we are building a client up inside of your.
And you might also recall, as we discussed in the last video, that we are invoking the child components
get initial props function right here.
So how about we say that whenever we are about to call the child's get initial props function?
Let's just take the client that we have already built and provide it as a second argument to get initial
props.
So for the child components, get initial props function.
I'm going to add in the client, which we already built up right there as a second argument.
I'm also going to take the current user do we fetch from right here and I'm going to provide that as
a third argument to get initial props.
This is just in case we ever decide that to fetch some data tied to a user.
We have to understand maybe who the users I.D. is or what the user's ideas are, something like that.
So as the third argument to get initial props, I will provide data dot current user.
Now, the reason that we are.
Referring to data current user right here is remember, whenever we fetch the current user using this
end point.
That gives us back an object that has the current user property in it.
And then that refers to the current user.
That's why we're referring to just current user right here.
Let's save that.
And now back inside of index dodgiest file.
If we need to get access to our clients, we can receive it as the second argument.
And if we need to get access to the current user just so we can use their I.D. to fetch some data or
something like that, we can receive it as the third argument.
All right.
That's it.
We're not going to do anything with this just right now inside this video.
But I hope that you can understand that now it's can be really easy for us to fetch some data using
this client argument right here or current user without having to make a follow up request to fetch
the current user.
And without having to import that build client function to build up a client, which we've already done
once before.
OK.
That is it.
Those are two improvements that I really just wanted to make on this next application.
Now that those two improvements are all done, we're gonna take one more pause and then start working
on our new routes in the next video.