From ad78ca4646c86f7c478e83a5541259ea481a4921 Mon Sep 17 00:00:00 2001 From: qkrxogmla Date: Sun, 11 May 2025 23:31:10 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EC=A0=84=EC=97=AD=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=84=B8=EC=85=98=EB=A7=8C=EB=A3=8C=EC=8B=9C=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=ED=8E=98=EC=9D=B4=EC=A7=80=EB=A1=9C=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/Deposit.jsx | 7 +++---- frontend/src/api/api.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 frontend/src/api/api.js 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; From e112d19e07e0e4f953446d6c44d437ba357c33c1 Mon Sep 17 00:00:00 2001 From: qkrxogmla Date: Sun, 11 May 2025 23:41:42 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fetch=20=EC=A0=88=EB=8C=80=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",