Skip to content

Instantly share code, notes, and snippets.

@benpickles
Created March 17, 2016 21:28
Show Gist options
  • Save benpickles/c8f4f45ebdce4bd4d878 to your computer and use it in GitHub Desktop.
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.
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