Great question. I imagine you're setting the network layer in your base component file. You could create a function wrapping the Relay.injectNetworkLayer call that updates the Auth header when you need to.
When loading the app, you could do something like this:
export function setNetworkLayer() {
return new Promise((resolve, reject) => {
var options = {};
if (localStorage.authToken) {
options.headers = {
Authorization: 'Basic ' + localStorage.authToken
}
}
else {
options.headers = {};
}
Relay.injectNetworkLayer(
new Relay.DefaultNetworkLayer('http://example.com/graphql', options)
);
resolve(options);
});
})
}
And if you wanted to update the network layer, you'd do something like this:
loginUser().then((res) => {
localStorage.authToken = res.token;
setNetworkLayer();
return;
})