From 096f3d821fbc0629f26f8628752964304b179cdb Mon Sep 17 00:00:00 2001 From: dohpark Date: Fri, 16 Dec 2022 11:32:39 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20401=20=EC=97=90=EB=9F=AC=EC=8B=9C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=95=84=EC=9B=83=20=EB=B2=84=ED=8A=BC=20=3D?= =?UTF-8?q?>=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EB=B2=84=ED=8A=BC=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/components/Error/index.tsx | 11 ++++++++--- client/src/pages/Edit/index.tsx | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/client/src/components/Error/index.tsx b/client/src/components/Error/index.tsx index 1cf477d..fb8ab9a 100644 --- a/client/src/components/Error/index.tsx +++ b/client/src/components/Error/index.tsx @@ -1,6 +1,7 @@ -import React, { useCallback, useEffect, useState } from "react"; +import React, { useCallback, useContext, useEffect, useState } from "react"; import axios from "axios"; import { useNavigate, useRouteError } from "react-router-dom"; +import { AuthContext } from "contexts/authProvider"; import FormLayout from "components/template/Layout"; import Button from "components/common/Button"; import theme from "styles/theme"; @@ -22,6 +23,7 @@ function Error() { const error = useRouteError() as ErrorType; const navigate = useNavigate(); + const { setAuth } = useContext(AuthContext); const [status, setStatus] = useState({ code: 404, message: "죄송합니다. 원하시는 페이지를 찾을 수가 없습니다." }); const errorIsAxiosError = useCallback( @@ -39,10 +41,13 @@ function Error() { else statusCode = error.status; if (statusCode === 400) setStatus({ code: 400, message: "죄송합니다. 페이지를 표시할 수 없습니다." }); - if (statusCode === 401) setStatus({ code: 401, message: "죄송합니다. 사용 권한이 없습니다. 로그인 부탁드립니다." }); + if (statusCode === 401) { + setStatus({ code: 401, message: "죄송합니다. 사용 권한이 없습니다. 로그인 부탁드립니다." }); + if (setAuth) setAuth({ userId: "", userName: "" }); + } if (statusCode === 404) setStatus({ code: 404, message: "죄송합니다. 원하시는 페이지를 찾을 수가 없습니다." }); if (statusCode === 500) setStatus({ code: 500, message: "죄송합니다. 페이지를 표시할 수 없습니다." }); - }, [error, errorIsAxiosError]); + }, [error, errorIsAxiosError, setAuth]); return ( diff --git a/client/src/pages/Edit/index.tsx b/client/src/pages/Edit/index.tsx index 2f2bdad..dadb2e3 100644 --- a/client/src/pages/Edit/index.tsx +++ b/client/src/pages/Edit/index.tsx @@ -1,7 +1,7 @@ /* eslint-disable no-param-reassign */ /* eslint-disable react/jsx-props-no-spreading */ import React, { useEffect, useReducer, useState } from "react"; -import { useNavigate, useParams } from "react-router-dom"; +import { useParams } from "react-router-dom"; import { useQuery } from "@tanstack/react-query"; import { DragDropContext, Droppable, Draggable, DropResult, DragStart } from "react-beautiful-dnd"; import { ToastContainer, toast } from "react-toastify";