Closed JeffSpies closed 2 years ago
@JeffSpies - I've been out of using this for some time, but I believe it is no longer necessary. The boot file now offers everything you need.
Scott
@smolinari If you happen to remember the option or pattern to dynamically add/change headers of the default client with information from the store post-boot, let me know, as that's what I'm trying to achieve.
@JeffSpies - You mean like this?
https://www.apollographql.com/docs/react/networking/authentication/#header
Scott
Yes, exactly, but I'd like that to happen globally on the default client in a dynamic way. For example, users aren't logged in at first, so one header is sent. Then they are logged in, and now a new header is sent. Some of the stuff sent has to come from the database and thus the store. I suppose I could write a wrapper for the client, but it seems less elegant than the v1 solution of using the apolloClientBeforeCreate hook. Again, maybe there's another pattern that I'm missing or perhaps I can update the client options post-login. I also thought about create two clients, one created post-login, but I don't think that's the desired pattern.
So, AFAIK, the authLink
function is ran by Apollo on every request. And, via the boot file, you can offer the store instance to that function and voila, your system is sending the token, when it should, once it is set in the store.
Scott
Closing issue. If you feel there is still a problem, you can reopen it with your reasoning.
Scott
I suspect I'm missing something, but I'm struggling to find the equivalent of the apolloClientBeforeCreate function from 1.0 in the v2 branch. Have those hooks been maintained? Thanks!