Last active
April 1, 2020 02:32
-
-
Save silasstoffel/016ccf2ac2d297799ae63119d0445cbc to your computer and use it in GitHub Desktop.
Axios - Config request interceptors for authorization Bearer
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"; | |
// 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