Migrated to http instance
This commit is contained in:
29
client/src/security/http.ts
Normal file
29
client/src/security/http.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import axios from "axios";
|
||||
import config from "../config";
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL: config.serverAddress,
|
||||
});
|
||||
|
||||
// Add a request interceptor
|
||||
instance.interceptors.request.use(
|
||||
function (config) {
|
||||
console.log("yessss");
|
||||
// Do something before request is sent
|
||||
let accessToken = localStorage.getItem("accessToken");
|
||||
if (accessToken) {
|
||||
config.headers["Authorization"] = `Bearer ${accessToken}`;
|
||||
}
|
||||
if (config.data && config.data.user) {
|
||||
delete config.data.user;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
function (error) {
|
||||
// Do something with request error
|
||||
|
||||
localStorage.clear();
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
export default instance;
|
||||
Reference in New Issue
Block a user