From c60432e6aa868ad1e5752d28292f4019ce3a0fa9 Mon Sep 17 00:00:00 2001 From: dbwhdtjr0457 Date: Thu, 30 Nov 2023 13:06:41 +0900 Subject: [PATCH 1/7] =?UTF-8?q?fix:=20eslint=20=EB=A7=9E=EC=B6=B0=20mainpa?= =?UTF-8?q?ge=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FE/src/pages/MainPage.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/FE/src/pages/MainPage.js b/FE/src/pages/MainPage.js index ea8c740..2fa6bc8 100644 --- a/FE/src/pages/MainPage.js +++ b/FE/src/pages/MainPage.js @@ -1,9 +1,7 @@ -/* eslint-disable */ - import React, { useEffect } from "react"; import { useQuery } from "react-query"; import styled from "styled-components"; -import { useRecoilState, useSetRecoilState, useRecoilValue } from "recoil"; +import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil"; import diaryAtom from "../atoms/diaryAtom"; import shapeAtom from "../atoms/shapeAtom"; import userAtom from "../atoms/userAtom"; @@ -17,7 +15,7 @@ import StarPage from "./StarPage"; function MainPage() { const [diaryState, setDiaryState] = useRecoilState(diaryAtom); const userState = useRecoilValue(userAtom); - const [shapeState, setShapeState] = useRecoilState(shapeAtom); + const setShapeState = useSetRecoilState(shapeAtom); const { refetch } = useQuery( "diaryList", @@ -60,13 +58,10 @@ function MainPage() { .then((res) => res.json()) .then(async (data) => { setShapeState(() => { - let shapeList = []; - for (let key in data) { - shapeList.push({ - uuid: data[key].uuid, - data: data[key].svg.replace(/<\?xml.*?\?>/, ""), - }); - } + const shapeList = Object.keys(data).map((key) => ({ + uuid: data[key].uuid, + data: data[key].svg.replace(/<\?xml.*?\?>/, ""), + })); return shapeList; }); }); From 86cb6f5580adc39fb3640abe2b3e1b4a3bda9ea3 Mon Sep 17 00:00:00 2001 From: dbwhdtjr0457 Date: Thu, 30 Nov 2023 15:21:00 +0900 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20403=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=8B=9C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=EB=A1=9C=20=EB=A6=AC=EB=8B=A4=EC=9D=B4=EB=A0=89?= =?UTF-8?q?=EC=85=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FE/.eslintrc.js | 1 + .../components/DiaryModal/DiaryCreateModal.js | 23 ++++--- .../components/DiaryModal/DiaryDeleteModal.js | 19 ++++- .../components/DiaryModal/DiaryReadModal.js | 21 ++++-- .../components/DiaryModal/DiaryUpdateModal.js | 53 ++++++++++---- FE/src/pages/MainPage.js | 69 ++++++++++++------- FE/src/utils/utils.js | 6 ++ 7 files changed, 138 insertions(+), 54 deletions(-) diff --git a/FE/.eslintrc.js b/FE/.eslintrc.js index 9851afb..9354f47 100644 --- a/FE/.eslintrc.js +++ b/FE/.eslintrc.js @@ -28,6 +28,7 @@ module.exports = { "react/prop-types": "off", "import/no-extraneous-dependencies": ["off"], "react/no-danger": "off", + "no-alert": "off", }, settings: { "import/resolver": { diff --git a/FE/src/components/DiaryModal/DiaryCreateModal.js b/FE/src/components/DiaryModal/DiaryCreateModal.js index 49c9765..0f22e9d 100644 --- a/FE/src/components/DiaryModal/DiaryCreateModal.js +++ b/FE/src/components/DiaryModal/DiaryCreateModal.js @@ -8,6 +8,7 @@ import shapeAtom from "../../atoms/shapeAtom"; import ModalWrapper from "../../styles/Modal/ModalWrapper"; import DiaryModalHeader from "../../styles/Modal/DiaryModalHeader"; import deleteIcon from "../../assets/deleteIcon.svg"; +import preventBeforeUnload from "../../utils/utils"; function DiaryCreateModal(props) { const { refetch } = props; @@ -27,15 +28,10 @@ function DiaryCreateModal(props) { }); useEffect(() => { - const handleBeforeUnload = (e) => { - e.preventDefault(); - e.returnValue = ""; - }; - - window.addEventListener("beforeunload", handleBeforeUnload); + window.addEventListener("beforeunload", preventBeforeUnload); return () => { - window.removeEventListener("beforeunload", handleBeforeUnload); + window.removeEventListener("beforeunload", preventBeforeUnload); }; }, []); @@ -69,7 +65,18 @@ function DiaryCreateModal(props) { }, body: JSON.stringify(data.diaryData), }) - .then((res) => res.json()) + .then((res) => { + if (res.status === 200) { + return res.json(); + } + if (res.status === 403) { + alert("로그인이 만료되었습니다. 다시 로그인해주세요."); + localStorage.removeItem("accessToken"); + sessionStorage.removeItem("accessToken"); + window.location.href = "/"; + } + return {}; + }) .then(() => { refetch(); setDiaryState((prev) => ({ diff --git a/FE/src/components/DiaryModal/DiaryDeleteModal.js b/FE/src/components/DiaryModal/DiaryDeleteModal.js index d5cac6e..ce3bcf2 100644 --- a/FE/src/components/DiaryModal/DiaryDeleteModal.js +++ b/FE/src/components/DiaryModal/DiaryDeleteModal.js @@ -19,9 +19,22 @@ function DiaryDeleteModal(props) { "Content-Type": "application/json", Authorization: `Bearer ${data.accessToken}`, }, - }).then(() => { - refetch(); - }); + }) + .then((res) => { + if (res.status === 200) { + return res; + } + if (res.status === 403) { + alert("로그인이 만료되었습니다. 다시 로그인해주세요."); + localStorage.removeItem("accessToken"); + sessionStorage.removeItem("accessToken"); + window.location.href = "/"; + } + return null; + }) + .then(() => { + refetch(); + }); } const { diff --git a/FE/src/components/DiaryModal/DiaryReadModal.js b/FE/src/components/DiaryModal/DiaryReadModal.js index 494476c..90fa484 100644 --- a/FE/src/components/DiaryModal/DiaryReadModal.js +++ b/FE/src/components/DiaryModal/DiaryReadModal.js @@ -49,7 +49,18 @@ async function getDiary(accessToken, diaryUuid) { "Content-Type": "application/json", Authorization: `Bearer ${accessToken}`, }, - }).then((res) => res.json()); + }).then((res) => { + if (res.status === 200) { + return res.json(); + } + if (res.status === 403) { + alert("로그인이 만료되었습니다. 다시 로그인해주세요."); + localStorage.removeItem("accessToken"); + sessionStorage.removeItem("accessToken"); + window.location.href = "/"; + } + return {}; + }); } function DiaryReadModal(props) { @@ -143,7 +154,7 @@ function DiaryReadModal(props) { 태그 - {data.tags.map((tag) => ( + {data.tags?.map((tag) => ( {tag} ))} @@ -151,9 +162,9 @@ function DiaryReadModal(props) { diff --git a/FE/src/components/DiaryModal/DiaryUpdateModal.js b/FE/src/components/DiaryModal/DiaryUpdateModal.js index 85d34df..949a449 100644 --- a/FE/src/components/DiaryModal/DiaryUpdateModal.js +++ b/FE/src/components/DiaryModal/DiaryUpdateModal.js @@ -8,6 +8,7 @@ import shapeAtom from "../../atoms/shapeAtom"; import ModalWrapper from "../../styles/Modal/ModalWrapper"; import DiaryModalHeader from "../../styles/Modal/DiaryModalHeader"; import deleteIcon from "../../assets/deleteIcon.svg"; +import preventBeforeUnload from "../../utils/utils"; async function getDiary(accessToken, diaryUuid) { return fetch(`http://223.130.129.145:3005/diaries/${diaryUuid}`, { @@ -16,7 +17,19 @@ async function getDiary(accessToken, diaryUuid) { "Content-Type": "application/json", Authorization: `Bearer ${accessToken}`, }, - }).then((res) => res.json()); + }).then((res) => { + if (res.status === 200) { + return res.json(); + } + if (res.status === 403) { + alert("로그인이 만료되었습니다. 다시 로그인해주세요."); + localStorage.removeItem("accessToken"); + sessionStorage.removeItem("accessToken"); + window.removeEventListener("beforeunload", preventBeforeUnload); + window.location.href = "/"; + } + return {}; + }); } // TODO: 일기 데이터 수정 API 연결 @@ -45,24 +58,34 @@ function DiaryUpdateModal(props) { Authorization: `Bearer ${data.accessToken}`, }, body: JSON.stringify(data.diaryData), - }).then(() => { - refetch(); - setDiaryState((prev) => ({ - ...prev, - isLoading: true, - })); - }); + }) + .then((res) => { + if (res.status === 200) { + return res; + } + if (res.status === 403) { + alert("로그인이 만료되었습니다. 다시 로그인해주세요."); + localStorage.removeItem("accessToken"); + sessionStorage.removeItem("accessToken"); + window.removeEventListener("beforeunload", preventBeforeUnload); + window.location.href = "/"; + } + return null; + }) + .then(() => { + refetch(); + setDiaryState((prev) => ({ + ...prev, + isLoading: true, + })); + }); } useEffect(() => { - const handleBeforeUnload = (e) => { - e.preventDefault(); - e.returnValue = ""; - }; - window.addEventListener("beforeunload", handleBeforeUnload); + window.addEventListener("beforeunload", preventBeforeUnload); return () => { - window.removeEventListener("beforeunload", handleBeforeUnload); + window.removeEventListener("beforeunload", preventBeforeUnload); }; }, []); @@ -166,7 +189,7 @@ function DiaryUpdateModal(props) { } /> - {diaryData.tags.map((tag) => ( + {diaryData.tags?.map((tag) => ( { diff --git a/FE/src/pages/MainPage.js b/FE/src/pages/MainPage.js index 2fa6bc8..2487d4f 100644 --- a/FE/src/pages/MainPage.js +++ b/FE/src/pages/MainPage.js @@ -1,3 +1,5 @@ +/* eslint-disable */ + import React, { useEffect } from "react"; import { useQuery } from "react-query"; import styled from "styled-components"; @@ -11,11 +13,13 @@ import DiaryListModal from "../components/DiaryModal/DiaryListModal"; import DiaryUpdateModal from "../components/DiaryModal/DiaryUpdateModal"; import DiaryLoadingModal from "../components/DiaryModal/DiaryLoadingModal"; import StarPage from "./StarPage"; +import preventBeforeUnload from "../utils/utils"; function MainPage() { const [diaryState, setDiaryState] = useRecoilState(diaryAtom); const userState = useRecoilValue(userAtom); const setShapeState = useSetRecoilState(shapeAtom); + const [loaded, setLoaded] = React.useState(false); const { refetch } = useQuery( "diaryList", @@ -26,7 +30,20 @@ function MainPage() { "Content-Type": "application/json", Authorization: `Bearer ${userState.accessToken}`, }, - }).then((res) => res.json()), + }).then((res) => { + if (res.status === 200) { + setLoaded(true); + return res.json(); + } + if (res.status === 403) { + alert("로그인이 만료되었습니다. 다시 로그인해주세요."); + localStorage.removeItem("accessToken"); + sessionStorage.removeItem("accessToken"); + window.removeEventListener("beforeunload", preventBeforeUnload); + window.location.href = "/"; + } + return {}; + }), { onSuccess: (data) => { setDiaryState((prev) => ({ ...prev, diaryList: data })); @@ -67,30 +84,36 @@ function MainPage() { }); } - getShapeFn(); - }, []); + if (loaded) { + getShapeFn(); + } + }, [loaded]); return ( - <> - { - e.preventDefault(); - setDiaryState((prev) => ({ - ...prev, - isCreate: true, - isRead: false, - isUpdate: false, - isList: false, - })); - }} - /> - - {diaryState.isCreate ? : null} - {diaryState.isRead ? : null} - {diaryState.isUpdate ? : null} - {diaryState.isList ? : null} - {diaryState.isLoading ? : null} - +
+ {loaded ? ( + <> + { + e.preventDefault(); + setDiaryState((prev) => ({ + ...prev, + isCreate: true, + isRead: false, + isUpdate: false, + isList: false, + })); + }} + /> + + {diaryState.isCreate ? : null} + {diaryState.isRead ? : null} + {diaryState.isUpdate ? : null} + {diaryState.isList ? : null} + {diaryState.isLoading ? : null} + + ) : null} +
); } diff --git a/FE/src/utils/utils.js b/FE/src/utils/utils.js index e69de29..a4dd834 100644 --- a/FE/src/utils/utils.js +++ b/FE/src/utils/utils.js @@ -0,0 +1,6 @@ +const preventBeforeUnload = (e) => { + e.preventDefault(); + e.returnValue = ""; +}; + +export default preventBeforeUnload; From 9c6b46c1e525df885f10b025c9b9fc15ff6ffe34 Mon Sep 17 00:00:00 2001 From: dbwhdtjr0457 Date: Thu, 30 Nov 2023 18:44:24 +0900 Subject: [PATCH 3/7] =?UTF-8?q?temp:=20git=20merge=20=EC=9D=B4=EC=A0=84=20?= =?UTF-8?q?commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/auth/auth.service.ts | 3 +- BE/src/auth/guard/auth.jwt-guard.ts | 2 + BE/src/auth/jwt.strategy.ts | 1 + .../components/DiaryModal/DiaryCreateModal.js | 2 +- .../components/DiaryModal/DiaryDeleteModal.js | 2 +- .../components/DiaryModal/DiaryReadModal.js | 2 +- .../components/DiaryModal/DiaryUpdateModal.js | 4 +- FE/src/components/LoginModal/LoginModal.js | 2 +- FE/src/components/SignUpModal/SignUpModal.js | 2 +- FE/src/pages/MainPage.js | 39 +++++++++++++++---- 10 files changed, 44 insertions(+), 15 deletions(-) diff --git a/BE/src/auth/auth.service.ts b/BE/src/auth/auth.service.ts index fabb852..242a330 100644 --- a/BE/src/auth/auth.service.ts +++ b/BE/src/auth/auth.service.ts @@ -35,7 +35,7 @@ export class AuthService { if (await bcrypt.compare(password, user.password)) { const accessTokenPayload = { userId }; const accessToken = await this.jwtService.sign(accessTokenPayload, { - expiresIn: "1h", + expiresIn: "5s", }); const refreshTokenPayload = { @@ -65,6 +65,7 @@ export class AuthService { ): Promise { const userId = user.userId; const accessTokenPayload = { userId }; + console.log(accessTokenPayload); const accessToken = await this.jwtService.sign(accessTokenPayload, { expiresIn: "1h", }); diff --git a/BE/src/auth/guard/auth.jwt-guard.ts b/BE/src/auth/guard/auth.jwt-guard.ts index 620c074..6e6bcdf 100644 --- a/BE/src/auth/guard/auth.jwt-guard.ts +++ b/BE/src/auth/guard/auth.jwt-guard.ts @@ -32,6 +32,7 @@ export class JwtAuthGuard extends NestAuthGuard("jwt") { } else if (err.message === "refresh expired") { throw new ForbiddenException("리프레쉬 토큰이 만료되었습니다."); } + console.log(err.message); throw new ForbiddenException("유효하지 않은 리프레쉬 토큰입니다."); } return user; @@ -46,6 +47,7 @@ export class JwtAuthGuard extends NestAuthGuard("jwt") { const request = context.switchToHttp().getRequest(); const requestIp = request.ip; const accessToken = request.headers.authorization.split(" ")[1]; + console.log(accessToken); const refreshToken = await this.redisClient.get(request.user.userId); diff --git a/BE/src/auth/jwt.strategy.ts b/BE/src/auth/jwt.strategy.ts index f72c603..0878e29 100644 --- a/BE/src/auth/jwt.strategy.ts +++ b/BE/src/auth/jwt.strategy.ts @@ -24,6 +24,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) { } async validate(payload: any): Promise { + console.log(payload); if (!payload) { throw new UnauthorizedException(); } diff --git a/FE/src/components/DiaryModal/DiaryCreateModal.js b/FE/src/components/DiaryModal/DiaryCreateModal.js index 0f22e9d..c2f4403 100644 --- a/FE/src/components/DiaryModal/DiaryCreateModal.js +++ b/FE/src/components/DiaryModal/DiaryCreateModal.js @@ -57,7 +57,7 @@ function DiaryCreateModal(props) { }; async function createDiaryFn(data) { - return fetch("http://223.130.129.145:3005/diaries", { + return fetch("http://localhost:3005/diaries", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/FE/src/components/DiaryModal/DiaryDeleteModal.js b/FE/src/components/DiaryModal/DiaryDeleteModal.js index ce3bcf2..33467a9 100644 --- a/FE/src/components/DiaryModal/DiaryDeleteModal.js +++ b/FE/src/components/DiaryModal/DiaryDeleteModal.js @@ -13,7 +13,7 @@ function DiaryDeleteModal(props) { const setDiaryState = useSetRecoilState(diaryAtom); async function deleteDiaryFn(data) { - return fetch(`http://223.130.129.145:3005/diaries/${data.diaryUuid}`, { + return fetch(`http://localhost:3005/diaries/${data.diaryUuid}`, { method: "DELETE", headers: { "Content-Type": "application/json", diff --git a/FE/src/components/DiaryModal/DiaryReadModal.js b/FE/src/components/DiaryModal/DiaryReadModal.js index 90fa484..f059555 100644 --- a/FE/src/components/DiaryModal/DiaryReadModal.js +++ b/FE/src/components/DiaryModal/DiaryReadModal.js @@ -43,7 +43,7 @@ function DiaryModalEmotionIndicator({ emotion }) { } async function getDiary(accessToken, diaryUuid) { - return fetch(`http://223.130.129.145:3005/diaries/${diaryUuid}`, { + return fetch(`http://localhost:3005/diaries/${diaryUuid}`, { method: "GET", headers: { "Content-Type": "application/json", diff --git a/FE/src/components/DiaryModal/DiaryUpdateModal.js b/FE/src/components/DiaryModal/DiaryUpdateModal.js index 949a449..c84ecd3 100644 --- a/FE/src/components/DiaryModal/DiaryUpdateModal.js +++ b/FE/src/components/DiaryModal/DiaryUpdateModal.js @@ -11,7 +11,7 @@ import deleteIcon from "../../assets/deleteIcon.svg"; import preventBeforeUnload from "../../utils/utils"; async function getDiary(accessToken, diaryUuid) { - return fetch(`http://223.130.129.145:3005/diaries/${diaryUuid}`, { + return fetch(`http://localhost:3005/diaries/${diaryUuid}`, { method: "GET", headers: { "Content-Type": "application/json", @@ -51,7 +51,7 @@ function DiaryUpdateModal(props) { }); async function updateDiaryFn(data) { - return fetch("http://223.130.129.145:3005/diaries", { + return fetch("http://localhost:3005/diaries", { method: "PUT", headers: { "Content-Type": "application/json", diff --git a/FE/src/components/LoginModal/LoginModal.js b/FE/src/components/LoginModal/LoginModal.js index b86036b..30ac97d 100644 --- a/FE/src/components/LoginModal/LoginModal.js +++ b/FE/src/components/LoginModal/LoginModal.js @@ -21,7 +21,7 @@ function LoginModal() { const errorRef = useRef(); const { mutate: login } = useMutation(() => { - fetch("http://223.130.129.145:3005/auth/signin", { + fetch("http://localhost:3005/auth/signin", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/FE/src/components/SignUpModal/SignUpModal.js b/FE/src/components/SignUpModal/SignUpModal.js index 64fbb49..9eca4f2 100644 --- a/FE/src/components/SignUpModal/SignUpModal.js +++ b/FE/src/components/SignUpModal/SignUpModal.js @@ -19,7 +19,7 @@ function SignUpModal() { const errorRef = useRef(); const { mutate: signUp } = useMutation(() => { - fetch("http://223.130.129.145:3005/auth/signup", { + fetch("http://localhost:3005/auth/signup", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/FE/src/pages/MainPage.js b/FE/src/pages/MainPage.js index 2487d4f..c3a1937 100644 --- a/FE/src/pages/MainPage.js +++ b/FE/src/pages/MainPage.js @@ -17,14 +17,15 @@ import preventBeforeUnload from "../utils/utils"; function MainPage() { const [diaryState, setDiaryState] = useRecoilState(diaryAtom); - const userState = useRecoilValue(userAtom); + const [userState, setUserState] = useRecoilState(userAtom); const setShapeState = useSetRecoilState(shapeAtom); const [loaded, setLoaded] = React.useState(false); const { refetch } = useQuery( - "diaryList", - () => - fetch("http://223.130.129.145:3005/diaries", { + ["diaryList", userState.accessToken], + () => { + console.log(userState.accessToken); + return fetch("http://localhost:3005/diaries", { method: "GET", headers: { "Content-Type": "application/json", @@ -37,17 +38,41 @@ function MainPage() { } if (res.status === 403) { alert("로그인이 만료되었습니다. 다시 로그인해주세요."); + localStorage.removeItem("accessToken"); sessionStorage.removeItem("accessToken"); window.removeEventListener("beforeunload", preventBeforeUnload); - window.location.href = "/"; + } + if (res.status === 401) { + return fetch("http://localhost:3005/auth/reissue", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${userState.accessToken}`, + }, + }) + .then((res) => res.json()) + .then((data) => { + if (localStorage.getItem("accessToken")) { + localStorage.setItem("accessToken", data.accessToken); + } + if (sessionStorage.getItem("accessToken")) { + sessionStorage.setItem("accessToken", data.accessToken); + } + setUserState((prev) => ({ + ...prev, + accessToken: data.accessToken, + })); + }); } return {}; - }), + }); + }, { onSuccess: (data) => { setDiaryState((prev) => ({ ...prev, diaryList: data })); }, + refetchOnWindowFocus: false, }, ); @@ -65,7 +90,7 @@ function MainPage() { }); async function getShapeFn() { - return fetch("http://223.130.129.145:3005/shapes/", { + return fetch("http://localhost:3005/shapes/", { method: "GET", headers: { "Content-Type": "application/json", From 7f0bf06f8ae10d0314c69e666d0b6335dc4d3a96 Mon Sep 17 00:00:00 2001 From: dbwhdtjr0457 Date: Thu, 30 Nov 2023 19:38:44 +0900 Subject: [PATCH 4/7] temp --- BE/src/auth/auth.service.ts | 2 +- FE/.eslintrc.js | 1 + .../components/DiaryModal/DiaryCreateModal.js | 2 +- .../components/DiaryModal/DiaryReadModal.js | 30 ++++++++++++++++--- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/BE/src/auth/auth.service.ts b/BE/src/auth/auth.service.ts index bdd4b89..664247b 100644 --- a/BE/src/auth/auth.service.ts +++ b/BE/src/auth/auth.service.ts @@ -72,7 +72,7 @@ export class AuthService { const accessTokenPayload = { userId }; console.log(accessTokenPayload); const accessToken = await this.jwtService.sign(accessTokenPayload, { - expiresIn: "1h", + expiresIn: "5s", }); const refreshTokenPayload = { diff --git a/FE/.eslintrc.js b/FE/.eslintrc.js index 9354f47..35275b0 100644 --- a/FE/.eslintrc.js +++ b/FE/.eslintrc.js @@ -29,6 +29,7 @@ module.exports = { "import/no-extraneous-dependencies": ["off"], "react/no-danger": "off", "no-alert": "off", + "no-shadow": "off", }, settings: { "import/resolver": { diff --git a/FE/src/components/DiaryModal/DiaryCreateModal.js b/FE/src/components/DiaryModal/DiaryCreateModal.js index c2f4403..5235e5f 100644 --- a/FE/src/components/DiaryModal/DiaryCreateModal.js +++ b/FE/src/components/DiaryModal/DiaryCreateModal.js @@ -75,7 +75,7 @@ function DiaryCreateModal(props) { sessionStorage.removeItem("accessToken"); window.location.href = "/"; } - return {}; + throw new Error("일기 작성에 실패했습니다."); }) .then(() => { refetch(); diff --git a/FE/src/components/DiaryModal/DiaryReadModal.js b/FE/src/components/DiaryModal/DiaryReadModal.js index f059555..3a31a86 100644 --- a/FE/src/components/DiaryModal/DiaryReadModal.js +++ b/FE/src/components/DiaryModal/DiaryReadModal.js @@ -42,7 +42,7 @@ function DiaryModalEmotionIndicator({ emotion }) { ); } -async function getDiary(accessToken, diaryUuid) { +async function getDiary(accessToken, diaryUuid, setUserState) { return fetch(`http://localhost:3005/diaries/${diaryUuid}`, { method: "GET", headers: { @@ -59,6 +59,28 @@ async function getDiary(accessToken, diaryUuid) { sessionStorage.removeItem("accessToken"); window.location.href = "/"; } + if (res.status === 401) { + return fetch("http://localhost:3005/auth/reissue", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${accessToken}`, + }, + }) + .then((res) => res.json()) + .then((data) => { + if (localStorage.getItem("accessToken")) { + localStorage.setItem("accessToken", data.accessToken); + } + if (sessionStorage.getItem("accessToken")) { + sessionStorage.setItem("accessToken", data.accessToken); + } + setUserState((prev) => ({ + ...prev, + accessToken: data.accessToken, + })); + }); + } return {}; }); } @@ -66,12 +88,12 @@ async function getDiary(accessToken, diaryUuid) { function DiaryReadModal(props) { const { refetch } = props; const [diaryState, setDiaryState] = useRecoilState(diaryAtom); - const userState = useRecoilValue(userAtom); + const [userState, setUserState] = useRecoilState(userAtom); const shapeState = useRecoilValue(shapeAtom); const [shapeData, setShapeData] = React.useState(""); const { data, isLoading, isError } = useQuery( - "diary", - () => getDiary(userState.accessToken, diaryState.diaryUuid), + ["diary", userState.accessToken], + () => getDiary(userState.accessToken, diaryState.diaryUuid, setUserState), { onSuccess: (loadedData) => { const foundShapeData = shapeState.find( From d696acf884c81f5ff4b32a45ac38f389c44066bf Mon Sep 17 00:00:00 2001 From: dbwhdtjr0457 Date: Thu, 30 Nov 2023 19:41:44 +0900 Subject: [PATCH 5/7] =?UTF-8?q?feat:=20401=20error=20=EC=8B=9C=20=EC=83=88?= =?UTF-8?q?=EB=A1=9C=20accessToken=20=EC=9A=94=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FE/src/components/DiaryModal/DiaryCreateModal.js | 2 +- FE/src/components/DiaryModal/DiaryDeleteModal.js | 2 +- FE/src/components/DiaryModal/DiaryReadModal.js | 4 ++-- FE/src/components/DiaryModal/DiaryUpdateModal.js | 4 ++-- FE/src/components/LoginModal/LoginModal.js | 2 +- FE/src/components/SignUpModal/SignUpModal.js | 2 +- FE/src/pages/MainPage.js | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/FE/src/components/DiaryModal/DiaryCreateModal.js b/FE/src/components/DiaryModal/DiaryCreateModal.js index 5235e5f..6f9de52 100644 --- a/FE/src/components/DiaryModal/DiaryCreateModal.js +++ b/FE/src/components/DiaryModal/DiaryCreateModal.js @@ -57,7 +57,7 @@ function DiaryCreateModal(props) { }; async function createDiaryFn(data) { - return fetch("http://localhost:3005/diaries", { + return fetch("http://223.130.129.145:3005/diaries", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/FE/src/components/DiaryModal/DiaryDeleteModal.js b/FE/src/components/DiaryModal/DiaryDeleteModal.js index 33467a9..ce3bcf2 100644 --- a/FE/src/components/DiaryModal/DiaryDeleteModal.js +++ b/FE/src/components/DiaryModal/DiaryDeleteModal.js @@ -13,7 +13,7 @@ function DiaryDeleteModal(props) { const setDiaryState = useSetRecoilState(diaryAtom); async function deleteDiaryFn(data) { - return fetch(`http://localhost:3005/diaries/${data.diaryUuid}`, { + return fetch(`http://223.130.129.145:3005/diaries/${data.diaryUuid}`, { method: "DELETE", headers: { "Content-Type": "application/json", diff --git a/FE/src/components/DiaryModal/DiaryReadModal.js b/FE/src/components/DiaryModal/DiaryReadModal.js index 3a31a86..097ec37 100644 --- a/FE/src/components/DiaryModal/DiaryReadModal.js +++ b/FE/src/components/DiaryModal/DiaryReadModal.js @@ -43,7 +43,7 @@ function DiaryModalEmotionIndicator({ emotion }) { } async function getDiary(accessToken, diaryUuid, setUserState) { - return fetch(`http://localhost:3005/diaries/${diaryUuid}`, { + return fetch(`http://223.130.129.145:3005/diaries/${diaryUuid}`, { method: "GET", headers: { "Content-Type": "application/json", @@ -60,7 +60,7 @@ async function getDiary(accessToken, diaryUuid, setUserState) { window.location.href = "/"; } if (res.status === 401) { - return fetch("http://localhost:3005/auth/reissue", { + return fetch("http://223.130.129.145:3005/auth/reissue", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/FE/src/components/DiaryModal/DiaryUpdateModal.js b/FE/src/components/DiaryModal/DiaryUpdateModal.js index c84ecd3..949a449 100644 --- a/FE/src/components/DiaryModal/DiaryUpdateModal.js +++ b/FE/src/components/DiaryModal/DiaryUpdateModal.js @@ -11,7 +11,7 @@ import deleteIcon from "../../assets/deleteIcon.svg"; import preventBeforeUnload from "../../utils/utils"; async function getDiary(accessToken, diaryUuid) { - return fetch(`http://localhost:3005/diaries/${diaryUuid}`, { + return fetch(`http://223.130.129.145:3005/diaries/${diaryUuid}`, { method: "GET", headers: { "Content-Type": "application/json", @@ -51,7 +51,7 @@ function DiaryUpdateModal(props) { }); async function updateDiaryFn(data) { - return fetch("http://localhost:3005/diaries", { + return fetch("http://223.130.129.145:3005/diaries", { method: "PUT", headers: { "Content-Type": "application/json", diff --git a/FE/src/components/LoginModal/LoginModal.js b/FE/src/components/LoginModal/LoginModal.js index 30ac97d..b86036b 100644 --- a/FE/src/components/LoginModal/LoginModal.js +++ b/FE/src/components/LoginModal/LoginModal.js @@ -21,7 +21,7 @@ function LoginModal() { const errorRef = useRef(); const { mutate: login } = useMutation(() => { - fetch("http://localhost:3005/auth/signin", { + fetch("http://223.130.129.145:3005/auth/signin", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/FE/src/components/SignUpModal/SignUpModal.js b/FE/src/components/SignUpModal/SignUpModal.js index 9eca4f2..64fbb49 100644 --- a/FE/src/components/SignUpModal/SignUpModal.js +++ b/FE/src/components/SignUpModal/SignUpModal.js @@ -19,7 +19,7 @@ function SignUpModal() { const errorRef = useRef(); const { mutate: signUp } = useMutation(() => { - fetch("http://localhost:3005/auth/signup", { + fetch("http://223.130.129.145:3005/auth/signup", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/FE/src/pages/MainPage.js b/FE/src/pages/MainPage.js index c3a1937..9677d15 100644 --- a/FE/src/pages/MainPage.js +++ b/FE/src/pages/MainPage.js @@ -25,7 +25,7 @@ function MainPage() { ["diaryList", userState.accessToken], () => { console.log(userState.accessToken); - return fetch("http://localhost:3005/diaries", { + return fetch("http://223.130.129.145:3005/diaries", { method: "GET", headers: { "Content-Type": "application/json", @@ -44,7 +44,7 @@ function MainPage() { window.removeEventListener("beforeunload", preventBeforeUnload); } if (res.status === 401) { - return fetch("http://localhost:3005/auth/reissue", { + return fetch("http://223.130.129.145:3005/auth/reissue", { method: "POST", headers: { "Content-Type": "application/json", @@ -90,7 +90,7 @@ function MainPage() { }); async function getShapeFn() { - return fetch("http://localhost:3005/shapes/", { + return fetch("http://223.130.129.145:3005/shapes/", { method: "GET", headers: { "Content-Type": "application/json", From 3ac9fe71f8f643699b9c676f7f5e77a4fd357dc0 Mon Sep 17 00:00:00 2001 From: dbwhdtjr0457 Date: Thu, 30 Nov 2023 19:44:07 +0900 Subject: [PATCH 6/7] =?UTF-8?q?fix:=20console=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/auth/auth.service.ts | 5 ++--- FE/src/pages/MainPage.js | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/BE/src/auth/auth.service.ts b/BE/src/auth/auth.service.ts index 664247b..e5b20e5 100644 --- a/BE/src/auth/auth.service.ts +++ b/BE/src/auth/auth.service.ts @@ -36,7 +36,7 @@ export class AuthService { if (await bcrypt.compare(password, user.password)) { const accessTokenPayload = { userId }; const accessToken = await this.jwtService.sign(accessTokenPayload, { - expiresIn: "5s", + expiresIn: "1h", }); const refreshTokenPayload = { @@ -70,9 +70,8 @@ export class AuthService { const userId = expiredResult.userId; const accessTokenPayload = { userId }; - console.log(accessTokenPayload); const accessToken = await this.jwtService.sign(accessTokenPayload, { - expiresIn: "5s", + expiresIn: "1h", }); const refreshTokenPayload = { diff --git a/FE/src/pages/MainPage.js b/FE/src/pages/MainPage.js index 9677d15..70cb826 100644 --- a/FE/src/pages/MainPage.js +++ b/FE/src/pages/MainPage.js @@ -24,7 +24,6 @@ function MainPage() { const { refetch } = useQuery( ["diaryList", userState.accessToken], () => { - console.log(userState.accessToken); return fetch("http://223.130.129.145:3005/diaries", { method: "GET", headers: { From d9bcb5056e4c06fc01224a081896e84e6cbf18f9 Mon Sep 17 00:00:00 2001 From: dbwhdtjr0457 Date: Thu, 30 Nov 2023 19:49:06 +0900 Subject: [PATCH 7/7] =?UTF-8?q?fix:=20console=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/auth/guard/auth.jwt-guard.ts | 3 +-- BE/src/auth/jwt.strategy.ts | 1 - BE/src/diaries/diaries.service.ts | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/BE/src/auth/guard/auth.jwt-guard.ts b/BE/src/auth/guard/auth.jwt-guard.ts index 6e6bcdf..e5f57ee 100644 --- a/BE/src/auth/guard/auth.jwt-guard.ts +++ b/BE/src/auth/guard/auth.jwt-guard.ts @@ -32,7 +32,7 @@ export class JwtAuthGuard extends NestAuthGuard("jwt") { } else if (err.message === "refresh expired") { throw new ForbiddenException("리프레쉬 토큰이 만료되었습니다."); } - console.log(err.message); + throw new ForbiddenException("유효하지 않은 리프레쉬 토큰입니다."); } return user; @@ -47,7 +47,6 @@ export class JwtAuthGuard extends NestAuthGuard("jwt") { const request = context.switchToHttp().getRequest(); const requestIp = request.ip; const accessToken = request.headers.authorization.split(" ")[1]; - console.log(accessToken); const refreshToken = await this.redisClient.get(request.user.userId); diff --git a/BE/src/auth/jwt.strategy.ts b/BE/src/auth/jwt.strategy.ts index 0878e29..f72c603 100644 --- a/BE/src/auth/jwt.strategy.ts +++ b/BE/src/auth/jwt.strategy.ts @@ -24,7 +24,6 @@ export class JwtStrategy extends PassportStrategy(Strategy) { } async validate(payload: any): Promise { - console.log(payload); if (!payload) { throw new UnauthorizedException(); } diff --git a/BE/src/diaries/diaries.service.ts b/BE/src/diaries/diaries.service.ts index 6907ff0..874b377 100644 --- a/BE/src/diaries/diaries.service.ts +++ b/BE/src/diaries/diaries.service.ts @@ -33,7 +33,6 @@ export class DiariesService { const tagEntities = await this.getTags(tags); const sentimentResult: SentimentDto = await this.getSentiment(content); - console.log(sentimentResult); const diary = await this.diariesRepository.createDiary( createDiaryDto, encryptedContent,