Skip to content

Commit 6cb377f

Browse files
committed
refact/작성자 UI 로직 수정
1 parent 6384f79 commit 6cb377f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/mocks/handlers.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,17 @@ type Comment = {
6161
}
6262

6363
/**
64-
* Authorization 토큰 유무만 체크 (지금 단계에선 “로그인 되어있다/아니다”만 필요)
64+
* Authorization 토큰 유무 또는 쿠키 유무 체크
6565
*/
6666
function isAuthenticated(request: Request): boolean {
6767
const authHeader = request.headers.get('Authorization')
68-
return authHeader?.startsWith('Bearer ') ?? false
68+
const hasToken = authHeader?.startsWith('Bearer ') ?? false
69+
70+
// 쿠키 방식 체크 (refreshToken 또는 accessToken)
71+
const cookie = request.headers.get('Cookie') || ''
72+
const hasCookie = cookie.includes('refreshToken') || cookie.includes('accessToken')
73+
74+
return hasToken || hasCookie
6975
}
7076

7177
/** =========================
@@ -380,8 +386,8 @@ export const handlers = [
380386
view_count: viewCount,
381387
created_at: post.created_at,
382388
updated_at: post.updated_at,
383-
is_liked: authenticated ? false : undefined,
384-
is_author: authenticated ? post.author.id === 1 : undefined,
389+
is_liked: authenticated ? false : undefined, // 연동 전엔 false
390+
is_author: authenticated ? (post.author.id === 1) : false,
385391
}
386392

387393
return HttpResponse.json(detail)

src/pages/community/CommunityDetailPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export default function CommunityDetailPage() {
7676
const loggedIn = isLoggedIn()
7777
const [currentUserId, setCurrentUserId] = useState<number | null>(null)
7878

79-
// 현재 로그인한 사용자가 게시글 작성자인지 확인
80-
const isAuthor = post && currentUserId !== null && post.author.id === currentUserId
79+
// 현재 로그인한 사용자가 게시글 작성자인지 확인 (서버 응답 우선, 로컬 검증 차선)
80+
const isAuthor = post?.is_author || (post && currentUserId !== null && post.author.id === currentUserId)
8181

8282
// 무한 스크롤
8383
const [page, setPage] = useState(1)

0 commit comments

Comments
 (0)