Skip to content

Commit

Permalink
feat: 무효 토큰 리다이렉트
Browse files Browse the repository at this point in the history
  • Loading branch information
bottlewook committed Feb 29, 2024
1 parent 8f8b9d6 commit 3bdf252
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/remote/queries/favorite/useFavoriteList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback } from 'react';

import { useInfiniteQuery } from '@tanstack/react-query';
import { useRouter } from 'next/navigation';

import { SearchFilterType } from '@constants/searchByMap';
import { getFavoriteList } from '@remote/api/requests/favorite/favorite.get.api';
Expand All @@ -9,6 +10,7 @@ import { ProductListInfoType } from '@remote/api/types/home';
const PAGE_SIZE = 10;

function useFavoriteList(sortType: SearchFilterType = 'recent-order') {
const router = useRouter();
const {
data, isLoading, fetchNextPage, isFetching, hasNextPage = false,
} = useInfiniteQuery<ProductListInfoType>({
Expand All @@ -30,6 +32,11 @@ function useFavoriteList(sortType: SearchFilterType = 'recent-order') {
suspense: true,
});

// 유효하지 않는 토큰인 경우
if (data?.pages[0].status === 401) {
router.push('/login');
}

const favoriteList = data?.pages.flatMap((page) => { return page.value.content; }) || [];

const loadMore = useCallback(async () => {
Expand Down

0 comments on commit 3bdf252

Please sign in to comment.