feat: introduce react-query and react-query-devtools

This commit is contained in:
Ali BARIN
2024-02-29 17:34:18 +00:00
parent 487c621fa5
commit 83815d3caa
8 changed files with 240 additions and 14 deletions

View File

@@ -0,0 +1,34 @@
import axios from 'axios';
import appConfig from 'config/app.js';
import * as URLS from 'config/urls.js';
import { getItem, removeItem } from 'helpers/storage.js';
const api = axios.create({
...axios.defaults,
baseURL: appConfig.restApiUrl,
headers: {
Authorization: getItem('token'),
},
});
api.interceptors.response.use(
(response) => response,
(error) => {
const status = error.response?.status;
if (status === 401) {
removeItem('token');
// hard reload to clear all state
if (window.location.pathname !== URLS.LOGIN) {
window.location.href = URLS.LOGIN;
}
}
// re-throw what's already intercepted here.
throw error;
},
);
export default api;

View File

@@ -1,8 +1,14 @@
const NAMESPACE = 'automatisch';
const makeKey = (key) => `${NAMESPACE}.${key}`;
export const setItem = (key, value) => {
return localStorage.setItem(makeKey(key), value);
};
export const getItem = (key) => {
return localStorage.getItem(makeKey(key));
};
export const removeItem = (key) => {
return localStorage.removeItem(makeKey(key));
};