Skip to content
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
13 changes: 13 additions & 0 deletions src/api/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/api/letter/letter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { authClient } from "../client";
import client, { authClient } from "../client";

// 편지 조회
export const getLetter = async (letterId: string) => {
Expand Down Expand Up @@ -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,
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/api/planet/space/space.tsx
Original file line number Diff line number Diff line change
@@ -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`);
};

// 전체 스페이스 목록 조회
Expand Down
59 changes: 33 additions & 26 deletions src/app/verify/letter/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ const VerifyLetter = () => {
};

useEffect(() => {
//액세스 토큰이 없을 때 미리 처리
if (!accessToken) {
router.push(url ? `/login?url=${url}` : `/login`);
return;
}

//액세스 토큰이 있다면
const checkMainIdAndVerify = async () => {
try {
// 메인 ID 조회를 통한 회원 검증 (탈퇴회원 포함)
Expand All @@ -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) {
Expand All @@ -106,30 +113,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);
}, []);

Expand Down