We are using the Axios to make an api call. Here is the global this Axios configuration. You can find it on this path src/@crema/services/auth/jwt-auth/index.js
We are using the Axios to make an api call. Here is the global this Axios configuration. You can find it on this path src/@crema/services/auth/jwt-auth/index.js
import axios from"axios";constjwtAxios=axios.create({ baseURL:"https://BACKEND_SERVER_ATH/api/",// YOUR_API_URL HERE headers: {"Content-Type":"application/json", },});jwtAxios.interceptors.response.use( (res) => res, (err) => {if (err.response &&err.response.data.msg ==="Token is not valid") {console.log("Need to logout user"); }returnPromise.reject(err); });exportconstsetAuthToken= (token) => {if (token) {jwtAxios.defaults.headers.common.Authorization =`Bearer ${token}`; //You can define any header params like Authorization based on the your requirementslocalStorage.setItem("token", token); } else {deletejwtAxios.defaults.headers.common.Authorization;localStorage.removeItem("token"); }};exportdefault jwtAxios;
We are using the mock APIs in our app, to gets the fake data from the Crema fake db. We are using axios-mock-adapter to achieve this. Here is the configuration of it.