This commit is contained in:
ct
2025-06-13 09:44:18 +08:00
parent 8d6e86ebb3
commit 2fd4d42aec
54 changed files with 9917 additions and 184 deletions

View File

@@ -0,0 +1,9 @@
// resources/js/Plugins/AxiosContext.js
import { createContext, useContext } from 'react';
import axiosInstance from './axios-plugin';
const AxiosContext = createContext();
export const AxiosProvider = ({ children }) => <AxiosContext.Provider value={axiosInstance}>{children}</AxiosContext.Provider>;
export const useAxios = () => useContext(AxiosContext);

View File

@@ -0,0 +1,23 @@
import axios from 'axios';
import { toast } from 'sonner';
const axiosInstance = axios.create({
withCredentials: true,
xsrfHeaderName: 'X-XSRF-TOKEN',
xsrfCookieName: 'XSRF-TOKEN',
});
axiosInstance.interceptors.response.use(
(response) => response,
(error) => {
//console.log(error);
if (error.response && error.response.status === 500) {
if (error?.response?.data?.message?.length > 0) {
toast.error(error.response.data.message + ' Please try again later.');
}
}
return Promise.reject(error);
},
);
export default axiosInstance;