Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 401 에러시 로그아웃 버튼 => 로그인 버튼으로 변경 #95

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions client/src/components/Error/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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(
Expand All @@ -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 (
<FormLayout backgroundColor="white">
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/Edit/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down