Skip to content

Instantly share code, notes, and snippets.

@silasstoffel
Last active April 1, 2020 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silasstoffel/016ccf2ac2d297799ae63119d0445cbc to your computer and use it in GitHub Desktop.
Save silasstoffel/016ccf2ac2d297799ae63119d0445cbc to your computer and use it in GitHub Desktop.
Axios - Config request interceptors for authorization Bearer
import axios from "axios";
// parameters of my configuration http
import httpConfig from "../config/http";
const http = axios.create({
baseURL: httpConfig.baseUrl
});
http.interceptors.request.use(
request => {
// your logic for get a token
const token = '';
if (token) {
request.headers.Authorization = `Bearer ${token}`;
}
return request;
},
err => {
return Promise.reject(err);
}
);
export default http;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment