Created
March 17, 2016 21:28
-
-
Save benpickles/c8f4f45ebdce4bd4d878 to your computer and use it in GitHub Desktop.
Inject an Authorization header into a redux-api-middleware request with a Redux middleware.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CALL_API } from 'redux-api-middleware' | |
export default function({ getState }) { | |
return function(next) { | |
return function(action) { | |
const callApi = action[CALL_API] | |
if (callApi) { | |
const { authToken } = getState() | |
callApi.headers = Object.assign({}, callApi.headers, { | |
Authorization: authToken, | |
}) | |
} | |
return next(action) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment