32 lines
819 B
TypeScript
32 lines
819 B
TypeScript
import axios from "axios";
|
|
import { getCookie } from "cookies-next";
|
|
import { toast } from "sonner";
|
|
|
|
const api = axios.create({ baseURL: "https://shahrbinapi.shetabdahi.ir/" });
|
|
|
|
axios.interceptors.request.use(function (config) {
|
|
const token = getCookie("Shahrbin_Token");
|
|
config.headers.Authorization = token ? `Bearer ${token}` : "";
|
|
return config;
|
|
});
|
|
|
|
api.interceptors.response.use(
|
|
function (response) {
|
|
console.log(response);
|
|
console.log(response.data?.data);
|
|
if (response.status == 200 || response.status == 201) {
|
|
if (response.data?.message) {
|
|
toast.success(response.data?.message);
|
|
}
|
|
}
|
|
return response;
|
|
},
|
|
function (error) {
|
|
console.log(error);
|
|
toast.error("مشکلی پیش آمد.");
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
export default api;
|