Skip to content

Commit afd4862

Browse files
committed
Chore: 불필요 코드 제거
1 parent 527827f commit afd4862

File tree

3 files changed

+45
-34
lines changed

3 files changed

+45
-34
lines changed

lib/api/link.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ export const getLinks = async () => {
4949
};
5050

5151
// 유저의 즐겨찾기 링크 조회(auth)
52-
export const getFavorites = async () => {
52+
export const getFavorites = async ({
53+
headers,
54+
}: {
55+
headers: Record<string, string>;
56+
}) => {
5357
try {
54-
const res = await proxy.get("/api/favorites");
58+
const res = await proxy.get("/api/favorites", { headers });
5559
if (res.status >= 200 && res.status < 300) return res.data;
5660
} catch (err) {
5761
console.error("에러 메시지: ", err instanceof Error ? err.message : err);

pages/api/favorites/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
66
const cookies = parse(req.headers.cookie || "");
77
const accessToken = cookies.accessToken;
88

9-
console.log("Received cookies:", cookies); // 쿠키 전체 확인
10-
console.log("Access Token:", accessToken); // accessToken 확인
11-
129
if (!accessToken) {
1310
return res.status(401).json({ message: "인증 오류: 토큰이 없습니다." });
1411
}

pages/favorite/index.tsx

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { GetServerSideProps } from "next";
1+
import { GetServerSideProps, GetServerSidePropsContext } from "next";
22
import { getFavorites } from "@/lib/api/link";
3-
import { useEffect, useState } from "react";
4-
import CardItem from "@/components/CardItem";
3+
import LinkCard from "@/components/LinkCard";
54
import CardsLayout from "@/components/Layout/CardsLayout";
65
import Container from "@/components/Layout/Container";
76

@@ -20,34 +19,45 @@ interface FavoriteProps {
2019
favoriteList: FavoriteDataType[];
2120
}
2221

23-
// 추후 severside 로 구현 예정
24-
// export const getServerSideProps: GetServerSideProps = async () => {
25-
// try {
26-
// const res = await getFavorites();
27-
// return { props: { favoriteList: res || [] } };
28-
// } catch (error) {
29-
// console.error("서버사이드에러", error);
30-
// return { props: { favoriteList: [] } };
31-
// }
32-
// };
22+
export const getServerSideProps: GetServerSideProps = async (
23+
context: GetServerSidePropsContext
24+
) => {
25+
const { req } = context;
3326

34-
const FavoritePage = () => {
35-
const [favoriteList, setFavoriteList] = useState<FavoriteDataType[]>([]);
27+
// 클라이언트의 쿠키 가져오기
28+
const cookies = req.headers.cookie || "";
3629

37-
useEffect(() => {
38-
const fetchFavorites = async () => {
39-
try {
40-
const data = await getFavorites();
41-
if (data) {
42-
setFavoriteList(data.list);
43-
}
44-
} catch (err) {
45-
console.error(err);
46-
}
47-
};
30+
try {
31+
const res = await getFavorites({
32+
headers: {
33+
Cookie: cookies, // 쿠키를 그대로 포함시킴
34+
},
35+
});
36+
return { props: { favoriteList: res.list || [] } };
37+
} catch (error) {
38+
console.error("서버사이드에러", error);
39+
return { props: { favoriteList: [] } };
40+
}
41+
};
42+
43+
const FavoritePage = ({ favoriteList }: FavoriteProps) => {
44+
// 임시 보류
45+
// const [favoriteList, setFavoriteList] = useState<FavoriteDataType[]>([]);
46+
47+
// useEffect(() => {
48+
// const fetchFavorites = async () => {
49+
// try {
50+
// const data = await getFavorites();
51+
// if (data) {
52+
// setFavoriteList(data.list);
53+
// }
54+
// } catch (err) {
55+
// console.error(err);
56+
// }
57+
// };
4858

49-
fetchFavorites();
50-
}, []);
59+
// fetchFavorites();
60+
// }, []);
5161

5262
return (
5363
<>
@@ -60,7 +70,7 @@ const FavoritePage = () => {
6070
<CardsLayout>
6171
{favoriteList.length > 0
6272
? favoriteList.map((favorite) => (
63-
<CardItem
73+
<LinkCard
6474
key={favorite.id}
6575
id={favorite.id}
6676
url={favorite.url}

0 commit comments

Comments
 (0)