Created
July 19, 2021 19:05
-
-
Save sroehrl/e8a51c521f32e392ac4278a38ff70f8d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let config = { | |
baseURL: process.env.apiRoute, //http://localhost:3000 | |
timeout: 8000, | |
headers: {'X-Custom-Header': 'wb-app'} | |
}; | |
const API = axios.create(config); | |
API.interceptors.request.use(exitingConfig => { | |
if(sessionStorage.token){ | |
exitingConfig.headers.Authorization = `Bearer ${localStorage.token.replace('"','')}`; | |
} | |
return exitingConfig; | |
}) | |
export default API; |
This file contains hidden or 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
<script type="module"> | |
import API from './api.js' | |
API.post('/login', obj).then(res => { | |
sessionStorage.token = res.data.token; // {token: 'qweq.123.asd'} | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment