Skip to content

Instantly share code, notes, and snippets.

@diego3g
Created October 24, 2018 12:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save diego3g/95ac6d9c5f641c889520c2671565f451 to your computer and use it in GitHub Desktop.
Save diego3g/95ac6d9c5f641c889520c2671565f451 to your computer and use it in GitHub Desktop.
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