From 435662a25709dd0dcbbedb10a45f00e8a3edb2a4 Mon Sep 17 00:00:00 2001 From: Seunghyo Date: Thu, 31 Oct 2024 23:59:12 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9Bfix:=20main=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=ED=86=A0=ED=81=B0=20=EB=A7=8C=EB=A3=8C=20=EC=9A=B0?= =?UTF-8?q?=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/client.tsx | 13 ++++++++++ src/api/planet/space/space.tsx | 4 +-- src/app/verify/letter/page.tsx | 46 +++++++++++++++++----------------- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/api/client.tsx b/src/api/client.tsx index 754d4759..0fe8e5d1 100644 --- a/src/api/client.tsx +++ b/src/api/client.tsx @@ -27,6 +27,19 @@ export const authClient = axios.create({ }, }); +client.interceptors.request.use( + (config) => { + const accessToken = getAccessToken(); + if (accessToken && config.headers) { + config.headers.Authorization = `Bearer ${accessToken}`; + } + return config; + }, + (error) => { + return Promise.reject(error); + } +); + authClient.interceptors.request.use( (config) => { const accessToken = getAccessToken(); diff --git a/src/api/planet/space/space.tsx b/src/api/planet/space/space.tsx index 39064c78..8dc19e74 100644 --- a/src/api/planet/space/space.tsx +++ b/src/api/planet/space/space.tsx @@ -1,8 +1,8 @@ -import { authClient } from "@/api/client"; +import client, { authClient } from "@/api/client"; // 메인 스페이스 아이디 조회 export const getMainId = async () => { - return await authClient.get(`/api/v1/spaces/main`); + return await client.get(`/api/v1/spaces/main`); }; // 전체 스페이스 목록 조회 diff --git a/src/app/verify/letter/page.tsx b/src/app/verify/letter/page.tsx index 498dfb37..1502c02d 100644 --- a/src/app/verify/letter/page.tsx +++ b/src/app/verify/letter/page.tsx @@ -106,30 +106,30 @@ const VerifyLetter = () => { //accessToken이 없는 상황이라면 로그인으로 //letterCode가 있다면 검증 진행 - if (url) { - verifyLetter(url) - .then((res) => { - if (res.data.letterId) { - //검증 성공하면 letterData를 받아온다 - setletterId(res.data.letterId); - fetchLetterData(res.data.letterId); - } - }) - .catch((error) => { - //검증 실패시 조회할 수 없는 편지 에러 페이지로 이동 - console.log(error); - router.push(url ? `/error/letter?url=${url}` : `/error/letter`); - }); - } + // if (url) { + // verifyLetter(url) + // .then((res) => { + // if (res.data.letterId) { + // //검증 성공하면 letterData를 받아온다 + // setletterId(res.data.letterId); + // fetchLetterData(res.data.letterId); + // } + // }) + // .catch((error) => { + // //검증 실패시 조회할 수 없는 편지 에러 페이지로 이동 + // console.log(error); + // router.push(url ? `/error/letter?url=${url}` : `/error/letter`); + // }); + // } - if (letterData === null) { - //LetterData 받아오는 로직 - for (let i = 0; i < LETTER_DATA.length; i++) { - if (LETTER_DATA[i].url === url) { - setLetterData(LETTER_DATA[i]); - } - } - } + // if (letterData === null) { + // //LetterData 받아오는 로직 + // for (let i = 0; i < LETTER_DATA.length; i++) { + // if (LETTER_DATA[i].url === url) { + // setLetterData(LETTER_DATA[i]); + // } + // } + // } setIsLoading(false); }, []); From c557f0be9ae516c0900a79108c7ca5ce8acce353 Mon Sep 17 00:00:00 2001 From: Seunghyo Date: Fri, 1 Nov 2024 00:05:45 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9Bfix:=20error=20status=20?= =?UTF-8?q?=EB=B3=84=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/letter/letter.tsx | 4 ++-- src/app/verify/letter/page.tsx | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/api/letter/letter.tsx b/src/api/letter/letter.tsx index 07d6e768..1942a5e6 100644 --- a/src/api/letter/letter.tsx +++ b/src/api/letter/letter.tsx @@ -1,4 +1,4 @@ -import { authClient } from "../client"; +import client, { authClient } from "../client"; // 편지 조회 export const getLetter = async (letterId: string) => { @@ -43,7 +43,7 @@ export const uploadImage = async ({ imageUrl }: { imageUrl: string }) => { // 편지 열람 가능 검증 export const verifyLetter = async (letterCode: string) => { - return await authClient.put(`/api/v1/letters/verify`, { + return await client.put(`/api/v1/letters/verify`, { letterCode: letterCode, }); }; diff --git a/src/app/verify/letter/page.tsx b/src/app/verify/letter/page.tsx index 1502c02d..d62f3cd0 100644 --- a/src/app/verify/letter/page.tsx +++ b/src/app/verify/letter/page.tsx @@ -67,11 +67,12 @@ const VerifyLetter = () => { }; useEffect(() => { + //액세스 토큰이 없을 때 미리 처리 if (!accessToken) { router.push(url ? `/login?url=${url}` : `/login`); return; } - + //액세스 토큰이 있다면 const checkMainIdAndVerify = async () => { try { // 메인 ID 조회를 통한 회원 검증 (탈퇴회원 포함) @@ -87,8 +88,14 @@ const VerifyLetter = () => { } }) .catch((error) => { - console.error("검증 실패:", error); - router.push(`/error/letter`); + if (error.status === 403) { + //해당 사용자가 열람 가능한 편지가 아님 + console.error("검증 실패:", error); + router.push(`/error/letter`); + } else if (error.status === 400) { + //편지가 존재하지 않음 + router.push(`/error`); + } }); } } catch (error) {