Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/app/movers/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export default async function MoversPage({ searchParams }: MoversPageProps) {
try {
// infinite query는 await 필수 (미대기 dehydrate 시 클라이언트 hydrate 깨질 수 있음)
await queryClient.prefetchInfiniteQuery({
queryKey: [...QUERY_KEYS.MOVERS.LIST, listQuery],
// 서버 prefetch에는 access token이 없으므로 guest 캐시로 분리합니다.
queryKey: [...QUERY_KEYS.MOVERS.LIST, "guest", listQuery],
queryFn: ({ pageParam }) => getMovers({ ...listQuery, page: pageParam }),
initialPageParam: 1,
getNextPageParam: (lastPage) =>
Expand Down
10 changes: 4 additions & 6 deletions src/components/mover/FavoriteMoversSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import Toast from "@/components/common/Toast/Toast";
import { Text } from "@/components/common/Text";
import MoverCard from "@/components/mover/MoverCard";
import { MoverCardSkeletonList } from "@/components/mover/MoverCardSkeleton";
import { useCustomerAuthReady } from "@/hooks/useCustomerAuthReady";
import { useFavoriteMovers } from "@/hooks/useFavoriteMovers";
import { useIsClient } from "@/hooks/useIsClient";
import { ChevronRightThinIcon } from "@/icons";
import { FAVORITE_MOVERS_SIDEBAR_LIMIT } from "@/lib/api/favorites";
import { getLoginRedirectPath, hasAuthSession } from "@/lib/auth/session";
import { getLoginRedirectPath } from "@/lib/auth/session";
import { APP_ROUTES } from "@/lib/constants/appRoutes";
import { mapMoverListItemToMover } from "@/lib/utils/mapMover";
import { cn } from "@/lib/utils/cn";
Expand Down Expand Up @@ -77,9 +77,7 @@ function FavoriteMoversSidebarStatus({
}

export function FavoriteMoversSidebar() {
// SSR/하이드레이션 전에는 토큰을 읽지 않아 서버·클라이언트 HTML을 동일하게 맞춤
const isClient = useIsClient();
const isLoggedIn = isClient && hasAuthSession();
const { isPending: isAuthPending, canFetch: isLoggedIn } = useCustomerAuthReady();
const query = useFavoriteMovers({
enabled: isLoggedIn,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
limit: FAVORITE_MOVERS_SIDEBAR_LIMIT,
Expand All @@ -88,7 +86,7 @@ export function FavoriteMoversSidebar() {

const movers =
query.data?.data.map(mapMoverListItemToMover).slice(0, FAVORITE_MOVERS_SIDEBAR_LIMIT) ?? [];
const showSkeleton = !isClient || (isLoggedIn && query.isPending);
const showSkeleton = isAuthPending || (isLoggedIn && query.isPending);
// 찜한 기사님이 1명 이상일 때부터 더보기 표시, 비로그인·빈 목록에서는 숨김
const showMoreLink = isLoggedIn && !query.isError && movers.length > 0;

Expand Down
6 changes: 5 additions & 1 deletion src/components/mover/MoversList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import MoversErrorPanel from "@/components/mover/MoversErrorPanel";
import { useMovers } from "@/hooks/useMovers";
import { mapMoverListItemToMover } from "@/lib/utils/mapMover";
import type { MoversSearchParamsState } from "@/lib/utils/moversSearchParams";
import { useAuthStore } from "@/stores/useAuthStore";

interface MoversListProps {
filters: MoversSearchParamsState;
Expand All @@ -30,6 +31,9 @@ const MOVERS_NEXT_PAGE_SKELETON_COUNT = 2;

export function MoversList({ filters }: MoversListProps) {
const query = useMovers(filters);
const hasHydrated = useAuthStore((state) => state.hasHydrated);
const isCheckingAuth = useAuthStore((state) => state.isCheckingAuth);
const isAuthPending = !hasHydrated || isCheckingAuth;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const sentinelRef = useRef<HTMLDivElement>(null);
const { hasNextPage, isFetchingNextPage, isFetchNextPageError, fetchNextPage, refetch } = query;
const [toastMessage, setToastMessage] = useState<string | null>(null);
Expand Down Expand Up @@ -57,7 +61,7 @@ export function MoversList({ filters }: MoversListProps) {
return () => observer.disconnect();
}, [hasNextPage, isFetchingNextPage, isFetchNextPageError, fetchNextPage]);

if (query.isPending) {
if (isAuthPending || query.isPending) {
return (
<MoverCardSkeletonList
variant="full"
Expand Down
17 changes: 10 additions & 7 deletions src/hooks/useMovers.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
"use client";

import { getMovers } from "@/lib/api/movers";
import { hasAuthSession } from "@/lib/auth/session";
import { QUERY_KEYS } from "@/lib/constants/queryKeys";
import { toMoversListQuery, type MoversSearchParamsState } from "@/lib/utils/moversSearchParams";
import { useApiInfiniteQuery } from "@/hooks/queries/useApiInfiniteQuery";
import { useIsClient } from "@/hooks/useIsClient";
import { useAuthStore } from "@/stores/useAuthStore";

const MOVERS_LIST_STALE_TIME_MS = 60 * 1000;

export function useMovers(filters: MoversSearchParamsState) {
const listQuery = toMoversListQuery(filters);
const isClient = useIsClient();
// SSR prefetch는 서버에 access token이 없어 비회원 응답일 수 있음 → 로그인 시 즉시 재검증
const staleTime = isClient && hasAuthSession() ? 0 : MOVERS_LIST_STALE_TIME_MS;
const hasHydrated = useAuthStore((state) => state.hasHydrated);
const isCheckingAuth = useAuthStore((state) => state.isCheckingAuth);
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
const isAuthReady = hasHydrated && !isCheckingAuth;
const authScope = isAuthenticated ? "authenticated" : "guest";
Comment thread
yooseohyeon marked this conversation as resolved.
Resolved

return useApiInfiniteQuery({
queryKey: [...QUERY_KEYS.MOVERS.LIST, listQuery],
queryKey: [...QUERY_KEYS.MOVERS.LIST, authScope, listQuery],
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
queryFn: ({ pageParam }) => getMovers({ ...listQuery, page: pageParam }),
initialPageParam: 1,
getNextPageParam: (lastPage) =>
lastPage.pagination.hasNext ? lastPage.pagination.page + 1 : undefined,
staleTime,
enabled: isAuthReady,
// 로그인 응답의 isFavorite는 세션 복구 직후 항상 서버에서 다시 확인합니다.
staleTime: isAuthenticated ? 0 : MOVERS_LIST_STALE_TIME_MS,
});
}