From f92b1ec83b3f2f71563ed13160120c8b1f68e242 Mon Sep 17 00:00:00 2001 From: zzz664 Date: Wed, 13 Dec 2023 23:31:58 +0900 Subject: [PATCH] =?UTF-8?q?addkeyword=20rt=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AddKeywordPage/AdminAddKeywordPage.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/frontend/src/pages/Admin/AddKeywordPage/AdminAddKeywordPage.js b/frontend/src/pages/Admin/AddKeywordPage/AdminAddKeywordPage.js index 50d7f8a..048f1d9 100644 --- a/frontend/src/pages/Admin/AddKeywordPage/AdminAddKeywordPage.js +++ b/frontend/src/pages/Admin/AddKeywordPage/AdminAddKeywordPage.js @@ -99,6 +99,31 @@ const AdminAddKeywordPage = () => { const onClickAdd = async (e) => { try { axios.defaults.headers.common["Authorization"] = `Bearer ${JSON.parse(window.sessionStorage.getItem("token_info")).access_token}`; + axios.interceptors.response.use( + (res) => { + return res; + }, + async (err) => { + const { + config, + response: { status }, + } = err; + + if(status === 401) { + if(err.response.data.message === "Unauthorized") { + const originReq = config; + const rtRes = await axios.get("https://"+process.env.REACT_APP_ADDRESS+"/auth/refresh"); + + window.sessionStorage.setItem("token_info", JSON.stringify(rtRes.data)); + axios.defaults.headers.common["Authorization"] = `Bearer ${JSON.parse(window.sessionStorage.getItem("token_info")).access_token}`; + originReq.headers["Authorization"] = `Bearer ${JSON.parse(window.sessionStorage.getItem("token_info")).access_token}`; + + return axios(originReq); + } + } + return Promise.reject(err); + } + ); const response = await axios.post( "https://"+process.env.REACT_APP_ADDRESS+"/keywords", { "name": keyword, "description": description, "memo": memo }, @@ -106,6 +131,8 @@ const AdminAddKeywordPage = () => { setIsSuccess(true); openModal(); } catch(err) { + if(err.response.status === 401) + navigate("/admin/login"); setIsSuccess(false); openModal(); }