로그인 백엔드 구현 및 로그인 프론트 기능 구현
This commit is contained in:
41
nuxt/composables/useAxios.ts
Normal file
41
nuxt/composables/useAxios.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import axios, { type AxiosError, type AxiosResponse } from 'axios';
|
||||
// import { useAuthStore } from '~/stores/login';
|
||||
// import { useDefaultStore, useLoadingStore } from '~/stores';
|
||||
|
||||
const baseURL = import.meta.env.VITE_API_URL as string;
|
||||
|
||||
export const useAxios = () => {
|
||||
// const loadingStore = useLoadingStore();
|
||||
// const defaultStore = useDefaultStore();
|
||||
// const { siteInfo } = storeToRefs(defaultStore);
|
||||
// const authStore = useAuthStore();
|
||||
const router = useRouter();
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL,
|
||||
withCredentials: true
|
||||
});
|
||||
|
||||
instance.interceptors.request.use(
|
||||
(config) => {
|
||||
return Promise.resolve(config);
|
||||
},
|
||||
(error: AxiosError) => {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
instance.interceptors.response.use(
|
||||
(response: AxiosResponse<any, any>) => {
|
||||
return Promise.resolve(response);
|
||||
},
|
||||
(error: AxiosError) => {
|
||||
if (error.status === 403) {
|
||||
return router.push('/');
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
return instance;
|
||||
};
|
||||
Reference in New Issue
Block a user