Last active
September 28, 2017 01:39
-
-
Save rob-mcgrail/e306888262efe8d1a47d060c882d12dd to your computer and use it in GitHub Desktop.
This file contains 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 axios from 'axios'; | |
import config from 'src/config'; | |
export default axios.create({ | |
baseURL: config.apiBaseUrl, | |
timeout: 3000, | |
headers: { | |
'content-type': 'application/json' | |
} | |
}); |
This file contains 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 { createStore, applyMiddleware, compose } from 'redux'; | |
import { createLogger } from 'redux-logger'; | |
import thunk from 'redux-thunk'; | |
import syncAxiosToken from './syncAxiosToken'; | |
import ApplicationReducer from './reducers'; | |
export default function (initialState = {}) { | |
const loggerMiddleware = createLogger(); | |
const middleware = [thunk, loggerMiddleware]; | |
const store = createStore( | |
ApplicationReducer, | |
initialState, | |
compose( | |
applyMiddleware(...middleware) | |
) | |
); | |
syncAxiosToken(store); | |
return store; | |
} |
This file contains 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 watch from 'redux-watch'; | |
import axios from 'src/axios'; | |
export default (store) => { | |
const w = watch(store.getState, 'auth.authentication'); | |
store.subscribe(w((token) => { | |
const authorization = token ? `Bearer ${token}` : ''; | |
axios.defaults.headers.common.Authorization = authorization; | |
})); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment