diff --git a/frontend/src/Deposit.jsx b/frontend/src/Deposit.jsx index 500de27..3a84615 100644 --- a/frontend/src/Deposit.jsx +++ b/frontend/src/Deposit.jsx @@ -2,6 +2,7 @@ import Header from "./components/Header"; import styles from "./Deposit.module.css"; import axios from "axios"; import { useEffect, useState } from "react"; +import api from "./api/api"; const Deposit = () => { const [deposit, setDeposit] = useState(null); @@ -12,10 +13,8 @@ const Deposit = () => { if (!userId) return; - axios - .get(`/api/deposit/${userId}`, { - withCredentials: true, // 세션 쿠키 포함 - }) + api + .get(`/deposit/${userId}`) .then((res) => setDeposit(res.data)) .catch((err) => { alert("보증금 정보를 불러오지 못했습니다."); diff --git a/frontend/src/api/api.js b/frontend/src/api/api.js new file mode 100644 index 0000000..814c063 --- /dev/null +++ b/frontend/src/api/api.js @@ -0,0 +1,19 @@ +import axios from "axios"; + +const api = axios.create({ + baseURL: "/api", + withCredentials: true, +}); + +// 401 오류 시 로그인 페이지로 리다이렉트 +api.interceptors.response.use( + (response) => response, + (error) => { + if (error.response?.status === 401) { + window.location.href = "/login"; + } + return Promise.reject(error); + } +); + +export default api; diff --git a/frontend/src/api/user.js b/frontend/src/api/user.js index 3964bac..749dc0a 100644 --- a/frontend/src/api/user.js +++ b/frontend/src/api/user.js @@ -1,5 +1,5 @@ export const loginUser = async ({ name, password }) => { - const res = await fetch("/api/login", { + const res = await fetch("http://www.pirocheck.org/login/login", { method: "POST", headers: { "Content-Type": "application/json",