-
-
Save hugoalmeidahh/aad5709a14baf2123ec73123ef0bb91d 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