svrcekmichal / redux-axios-middleware

Redux middleware for fetching data with axios HTTP client
MIT License
922 stars 96 forks source link

Authorisation header won't update #114

Closed pharmarin closed 4 years ago

pharmarin commented 4 years ago

Header will not update when I try to add JWT in Authorization header. interceptors: {

request: [
  ({ getState, dispatch, getSourceAction }, req) => {
    const needAuth = get(
      getSourceAction(req),
      'payload.request.auth',
    );
    if (needAuth) {
      const token = get(getState(), 'auth.tokens.access_token');
      req.headers.Authorization = `Bearer ${token}`;
    }
    return req;
  },
],

},

I tried to add other type of header and it works if I try to add random header. But when I want to change Authorization it fails.

pharmarin commented 4 years ago

I changed the auth value from action.payload.request.auth to action.auth and it solved the problem. Sorry for the inconvenience.