Created
October 24, 2018 12:52
-
-
Save diego3g/95ac6d9c5f641c889520c2671565f451 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 store from '~/store'; | |
const api = axios.create({ | |
baseURL: 'http://localhost:3333', | |
}); | |
api.interceptors.request.use((config) => { | |
const { token } = store.getState().auth; // Aqui poderia ser localStoraget.getItem | |
const headers = { ...config.headers }; | |
if (token) { | |
headers.Authorization = `Bearer ${token}`; | |
} | |
return { ...config, headers }; | |
}); | |
export default api; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment