Strategy for serving OAuth access token within Redux application
<p>I have a Redux app and a remote API that serves as an OAuth server. Based on typical routine, a user exchanges their credentials to a token that is then used by the app to fetch data and do some stuff on the server. This token is stored into the store and also into <code>sessionStorage</code>.</p>

<p>Now, sometimes an access token would expire, but since a refresh token has been received, it's better to attempt to refresh first, and only if it goes wrong, sign the user off.</p>

<p>I completely understand the signing-off part, which technically means simply dispatching a certain action. But how can I simplify the token refreshment routine?</p>

<p>I tried redux-saga, but it's very verbose. I literally have to partially duplicate the code for every action that depends on remote API, to make sure every request like that would first check access token and whether it hasn't yet expired, and manage to refresh it otherwise.</p>

<p>Another thing I tried to do is a middleware that would expect a certain type of action with a request to remote API wrapped into Promise. This kind of works, but I'm curious if there's another way to do.</p>

<p>Has anybody ever implemented this (pretty generic) kind of thing? Any ideas how to automate token refreshment and not get mad with increased amount of code? Maybe higher-order component?</p>