relay-tools / react-relay-network-layer

ReactRelayNetworkLayer with middlewares and query batching for Relay Classic.
MIT License
277 stars 47 forks source link

authMiddleware stop working as of 2.0.0! #42

Closed carlrosell closed 7 years ago

carlrosell commented 7 years ago

I noticed that the auth middleware just stopped working when updating to v2.0.0.

Here is the working config that was used before:

export const networkLayer = (store: Store<*, *>): RelayNetworkLayer =>
  new RelayNetworkLayer(
    [
      urlMiddleware({ url: graphQLURL }),
      authMiddleware({
        token: () => store.getState().auth.accessToken,
        tokenRefreshPromise: () => refreshToken(store.dispatch),
      }),
      next =>
        req => {
          req.headers['X-Stats-Timeout'] = statisticsTimeout;
          return next(req);
        },
    ],
    { disableBatchQuery: true },
  );

I then removed the batchQuery config as it was moved to another middleware but the auth middleware stopped working. It crashes on the, recently added, thrown error inside of the fetchWithMiddlewares-function https://github.com/nodkz/react-relay-network-layer/blob/master/src/fetchWithMiddleware.js#L25.

By throwing there the 401 error does not reach the 401 check inside of the authMiddleweare.

If you need more info just let me know ๐Ÿ˜„

nodkz commented 7 years ago

Thanks for reporting. Please check new version. Should be published in a couple of minutes.

carlrosell commented 7 years ago

That was fast ๐Ÿ‘ Thanks