Skip to content

Commit eb20d6c

Browse files
committed
401에러 로그인추가
1 parent 28b5eb0 commit eb20d6c

File tree

9 files changed

+22
-14
lines changed

9 files changed

+22
-14
lines changed

src/domains/community/api/fetchComment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const fetchComment = async (postId: ParamValue | number): Promise<Comment
77
const res = await fetch(`${getApi}/posts/${postId}/comments`, {
88
method: 'GET',
99
cache: 'no-store', // 캐시 비활성화
10+
credentials: 'include',
1011
});
1112
const data = await res.json();
1213

src/domains/community/api/fetchPost.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export async function likePost(postId: number | ParamValue) {
9999
export async function getLikePost(postId: number | ParamValue) {
100100
const res = await fetch(`${getApi}/posts/${postId}/like`, {
101101
method: 'GET',
102+
credentials: 'include',
102103
});
103104
if (!res.ok) throw new Error('좋아요 실패');
104105
const data = await res.json();

src/domains/community/detail/DetailHeader.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ function DetailHeader({ categoryName, postId, userNickName }: Props) {
2828

2929
try {
3030
const res = await fetch(`${getApi}/posts/${postId}`, { method: 'DELETE' });
31-
if (res.ok) console.log('deleted');
3231
router.push('/community');
3332
} catch (err) {
3433
console.error(err);

src/domains/community/detail/DetailPage.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,22 @@ function DetailPage() {
4848

4949
useEffect(() => {
5050
const fetchLikeStatus = async () => {
51+
// 로그인 상태일 때만 좋아요 상태 조회
52+
if (!isLoggedIn) {
53+
setLike(false);
54+
return;
55+
}
56+
5157
try {
5258
const liked = await getLikePost(postId);
5359
setLike(liked);
5460
} catch (err) {
5561
console.error('좋아요 상태 불러오기 실패', err);
62+
setLike(false);
5663
}
5764
};
5865
fetchLikeStatus();
59-
}, [postId]);
66+
}, [postId, isLoggedIn]);
6067

6168
useEffect(() => {
6269
if (postDetail) {

src/domains/community/hook/useComment.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ export function useComments(postId: ParamValue, user: User | null) {
1515
} | null>(null);
1616

1717
const fetchData = useCallback(async () => {
18+
// 로그인 상태일 때만 댓글 조회
19+
if (!user) {
20+
setComments([]);
21+
return;
22+
}
23+
1824
const data = await fetchComment(postId);
1925
if (!data) return;
2026
setComments(data);
2127
setIsEnd(false);
22-
}, [postId]);
28+
}, [postId, user]);
2329

2430
useEffect(() => {
2531
fetchData();
26-
}, [postId]);
32+
}, [fetchData]);
2733

2834
const handleUpdateComment = async (commentId: number, content: string) => {
2935
if (!user) {
@@ -74,11 +80,13 @@ export function useComments(postId: ParamValue, user: User | null) {
7480
};
7581

7682
const loadMoreComments = async (lastCommentId: number) => {
77-
if (isEnd || isLoading) return;
83+
if (isEnd || isLoading || !user) return;
7884

7985
setIsLoading(true);
8086
try {
81-
const res = await fetch(`${getApi}/posts/${postId}/comments?lastId=${lastCommentId}`);
87+
const res = await fetch(`${getApi}/posts/${postId}/comments?lastId=${lastCommentId}`, {
88+
credentials: 'include',
89+
});
8290
const newComments = await res.json();
8391

8492
if (newComments.data.length === 0) {

src/domains/community/main/CommunityFilter.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ function CommunityFilter({ posts, setPosts }: Props) {
2525
const handleChange = async (selectTitle: string) => {
2626
if (!query) return;
2727

28-
console.log(selectTitle);
29-
3028
const data = await fetchPostByTab({
3129
category: query,
3230
filter: sortMap[selectTitle as keyof typeof sortMap],

src/domains/recipe/components/details/BackBtn.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ function BackButton() {
99
});
1010

1111
const handleBack = () => {
12-
console.log('뒤로가기 클릭');
13-
console.log('저장된 스크롤:', sessionStorage.getItem('cocktail_list_scroll'));
14-
console.log('저장된 URL:', sessionStorage.getItem('cocktail_list_scroll_url'));
15-
console.log('복원 플래그:', sessionStorage.getItem('cocktail_list_scroll_restore'));
1612
restoreAndGoBack();
1713
};
1814

src/domains/recipe/components/details/DetailsHeader.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ function DetailsHeader({ id, favor }: { id: number; favor: boolean | undefined }
2020
const url = async () => {
2121
const res = await fetch(`${getApi}/cocktails/${id}/share`);
2222
const json = await res.json();
23-
console.log(json.data);
2423
setMeta(json.data);
2524
};
2625

src/domains/shared/components/comment/CommentHeader.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ function CommentHeader({
6161
intervalCall1000(async () => {
6262
const success = await createComment(newComment);
6363
if (!success) {
64-
console.log('칵테일 페이지에서 댓글은 한개만 입력 가능합니다');
6564
}
6665
});
6766
}

0 commit comments

Comments
 (0)