source: my-react-app/src/axios_helper.js@ 8ca35dc

main
Last change on this file since 8ca35dc was 8ca35dc, checked in by Aleksandar Panovski <apano77@…>, 4 months ago

Done with stupid timeslots

  • Property mode set to 100644
File size: 884 bytes
Line 
1import axios from "axios";
2import data from "bootstrap/js/src/dom/data";
3axios.defaults.baseURL = 'http://localhost:8081'
4axios.defaults.headers.post["Content-Type"] = 'application/json'
5
6export const getAuthToken = () => {
7 return window.localStorage.getItem("auth_token");
8}
9
10export const request = (method, url, data) => {
11 let headers = {};
12 if(getAuthToken() !== null && getAuthToken() !== "null") {
13 headers = {"Authorization" : `Bearer ${getAuthToken()}`};
14 }
15
16 return axios({
17 method: method,
18 url: url,
19 data: data
20 })
21}
22
23export const setAuthToken = (token) => {
24 if (token) {
25 axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
26 localStorage.setItem('token', token);
27 } else {
28 delete axios.defaults.headers.common['Authorization'];
29 localStorage.removeItem('token');
30 }
31};
Note: See TracBrowser for help on using the repository browser.