-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: 흩어진 서버 prefetch 정리로 중복 API 호출 제거 #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e3e3de9
refactor: 유저 정보 서버 prefetch를 root layout으로 통합
iOdiO89 9f26190
refactor: ['me'] 쿼리 정의를 getMeQueryOptions와 QUERY_KEYS로 단일화
iOdiO89 c4d60e4
refactor: 하위 라우트의 hydration용 유저 정보 prefetch 제거
iOdiO89 1d65507
refactor: gating용 유저 조회를 ensureQueryData로 변경
iOdiO89 a3cb90d
refactor: 멤버 전용 gating을 토큰 role 클레임 판별로 전환
iOdiO89 dcbff0f
fix: 탈퇴 페이지 게스트 이상 진입 시 마이페이지로 복귀
iOdiO89 c28d42b
refactor: 홈 페이지의 중복 토너먼트 prefetch 제거
iOdiO89 6959f8a
refactor: 알림 페이지 서버 prefetch 제거 (배지 캐시 재사용)
iOdiO89 c8c8677
refactor: 알림 쿼리키를 QUERY_KEYS로 등록
iOdiO89 99e77f4
refactor: 알림 페이지 골격을 RSC로 분리
iOdiO89 87bec6f
Merge remote-tracking branch 'origin/dev' into refactor/491-duplicate…
iOdiO89 f8e4203
style: 알림 페이지 루트를 main 태그로 변경
iOdiO89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,26 @@ | ||
| import { HydrationBoundary, dehydrate } from '@tanstack/react-query'; | ||
| import { isAxiosError } from 'axios'; | ||
| import { headers } from 'next/headers'; | ||
| import { cookies, headers } from 'next/headers'; | ||
| import { redirect } from 'next/navigation'; | ||
|
|
||
| import { getMe } from '@/apis/getMe'; | ||
| import { QUERY_ACTION } from '@/consts/queryAction'; | ||
| import { ROUTES } from '@/consts/route'; | ||
| import type { ApiErrorResponseT } from '@/types/api'; | ||
| import { getRoleFromToken } from '@/utils/auth'; | ||
| import { getLoginPath } from '@/utils/loginRedirect'; | ||
| import { getQueryClient } from '@/utils/queryClient'; | ||
|
|
||
| async function MyPageMemberOnlyLayout({ children }: { children: React.ReactNode }) { | ||
| const headerStore = await headers(); | ||
| const redirectPath = headerStore.get('x-redirect-path'); | ||
| const queryClient = getQueryClient(); | ||
|
|
||
| /** 유저 정보 조회 */ | ||
| try { | ||
| const userData = await queryClient.fetchQuery({ | ||
| queryKey: ['me'], | ||
| queryFn: getMe, | ||
| }); | ||
| /** MEMBER 권한 판별 */ | ||
| const accessToken = (await cookies()).get('access_token')?.value; | ||
| const role = getRoleFromToken(accessToken); | ||
|
|
||
| if (userData.identityType !== 'MEMBER') redirect(ROUTES.LOGIN); | ||
| } catch (error) { | ||
| if (!isAxiosError<ApiErrorResponseT>(error)) throw error; | ||
| /** 토큰이 유효하지 않은 경우 세션 만료 처리 */ | ||
| if (role === null) redirect(getLoginPath(redirectPath, QUERY_ACTION.VALUE.SESSION_EXPIRED)); | ||
|
|
||
| if (error.response?.status === 401 || error.response?.status === 404) | ||
| redirect(getLoginPath(redirectPath, QUERY_ACTION.VALUE.SESSION_EXPIRED)); | ||
| /** 멤버가 아닌 경우 마이페이지로 리다이렉트 */ | ||
| if (role !== 'MEMBER') redirect(ROUTES.MYPAGE); | ||
|
|
||
| throw error; | ||
| } | ||
|
|
||
| return <HydrationBoundary state={dehydrate(queryClient)}>{children}</HydrationBoundary>; | ||
| return children; | ||
| } | ||
|
|
||
| export default MyPageMemberOnlyLayout; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.