-
Notifications
You must be signed in to change notification settings - Fork 0
[Fix] mypage redirect 로직 수정 #234
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,3 @@ | ||||||||||||||||||||||||||||
| import { redirect } from 'next/navigation'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import { dehydrate, HydrationBoundary } from '@tanstack/react-query'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import { API } from '@/api'; | ||||||||||||||||||||||||||||
|
|
@@ -10,17 +8,15 @@ interface Props { | |||||||||||||||||||||||||||
| children: React.ReactNode; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export const dynamic = 'force-dynamic'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const MyPageLayout = async ({ children }: Props) => { | ||||||||||||||||||||||||||||
| const queryClient = getQueryClient(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||
| await queryClient.fetchQuery({ | ||||||||||||||||||||||||||||
| queryKey: userKeys.me(), | ||||||||||||||||||||||||||||
| queryFn: () => API.userService.getMe(), | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||
| redirect('/login'); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| await queryClient.fetchQuery({ | ||||||||||||||||||||||||||||
| queryKey: userKeys.me(), | ||||||||||||||||||||||||||||
| queryFn: () => API.userService.getMe(), | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
Comment on lines
+16
to
+19
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. API 실패 시 에러 처리가 누락되었습니다. 이전에 존재하던 try/catch 에러 처리 로직이 제거되었습니다. 현재 코드에서는 사용자 경험 향상을 위해 에러 처리를 추가하거나, 최소한 적절한 에러 바운더리를 설정하는 것을 권장합니다. 🔎 에러 처리 추가 예시 const MyPageLayout = async ({ children }: Props) => {
const queryClient = getQueryClient();
- await queryClient.fetchQuery({
- queryKey: userKeys.me(),
- queryFn: () => API.userService.getMe(),
- });
+ try {
+ await queryClient.fetchQuery({
+ queryKey: userKeys.me(),
+ queryFn: () => API.userService.getMe(),
+ });
+ } catch (error) {
+ // 적절한 에러 처리 (예: 로그인 페이지로 리다이렉트)
+ redirect('/login');
+ }
return <HydrationBoundary state={dehydrate(queryClient)}>{children}</HydrationBoundary>;
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return <HydrationBoundary state={dehydrate(queryClient)}>{children}</HydrationBoundary>; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { redirect } from 'next/navigation'; | ||
| import { notFound, redirect } from 'next/navigation'; | ||
|
|
||
| import { dehydrate, HydrationBoundary } from '@tanstack/react-query'; | ||
|
|
||
|
|
@@ -15,22 +15,19 @@ const ProfileLayout = async ({ children, params }: Props) => { | |
| const { userId: id } = await params; | ||
| const userId = Number(id); | ||
|
|
||
| const { cookies } = await import('next/headers'); | ||
| const cookieStore = await cookies(); | ||
| const myId = Number(cookieStore.get('userId')?.value); | ||
|
|
||
| // 본인 id와 같은지 확인 후 같으면 mypage로 리다이렉트 | ||
| if (userId === myId) { | ||
| redirect('/mypage'); | ||
| } | ||
| // userId가 숫자가 아닌 경우 notFound redirect 처리 | ||
| if (isNaN(userId)) notFound(); | ||
|
|
||
| const queryClient = getQueryClient(); | ||
|
|
||
| await queryClient.fetchQuery({ | ||
| const user = await queryClient.fetchQuery({ | ||
| queryKey: userKeys.item(userId), | ||
| queryFn: () => API.userService.getUser({ userId }), | ||
| }); | ||
|
|
||
| // isFollow가 null이면 본인 페이지 이므로 mypage로 redirect 처리 | ||
| if (user.isFollow === null) redirect('/mypage'); | ||
|
Comment on lines
+23
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Find the getUser API implementation and schema
find . -type f -name "*.ts" -o -name "*.tsx" | head -20Repository: WeGo-Together/WeGo_FrontEnd Length of output: 692 🏁 Script executed: # Search for API service definition to understand getUser response
rg "getUser" --type ts --type tsx -A 5 | head -50Repository: WeGo-Together/WeGo_FrontEnd Length of output: 98 🏁 Script executed: # Look for userService implementation
rg "userService\|API\.user" --type ts --type tsx -B 2 -A 2 | head -50Repository: WeGo-Together/WeGo_FrontEnd Length of output: 98 🏁 Script executed: # Check the mypage layout for error handling pattern mentioned in review
find . -type f -name "*mypage*" -o -name "*layout.tsx" | grep -i mypageRepository: WeGo-Together/WeGo_FrontEnd Length of output: 132 🏁 Script executed: # Search for isFollow field usage in the codebase
rg "isFollow" --type ts --type tsx -B 3 -A 3Repository: WeGo-Together/WeGo_FrontEnd Length of output: 98 🏁 Script executed: # Search for getUser without type restriction
rg "getUser" -A 5 -B 2 | head -60Repository: WeGo-Together/WeGo_FrontEnd Length of output: 2794 🏁 Script executed: # Look for isFollow field in codebase
rg "isFollow" -A 3 -B 3 | head -80Repository: WeGo-Together/WeGo_FrontEnd Length of output: 4480 🏁 Script executed: # Check user service implementation
cat src/api/service/user-service/index.tsRepository: WeGo-Together/WeGo_FrontEnd Length of output: 2135 🏁 Script executed: # Check mypage layout for error handling
cat src/app/\(user\)/mypage/layout.tsxRepository: WeGo-Together/WeGo_FrontEnd Length of output: 706 🏁 Script executed: # Check the profile layout file
cat src/app/\(user\)/profile/\[userId\]/layout.tsxRepository: WeGo-Together/WeGo_FrontEnd Length of output: 1054
현재 코드에서 참고: 🤖 Prompt for AI Agents |
||
|
|
||
| return <HydrationBoundary state={dehydrate(queryClient)}>{children}</HydrationBoundary>; | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ export interface User { | |
| groupCreatedCnt: number; | ||
| isNotificationEnabled: boolean; | ||
| createdAt: string; | ||
| isFollow: boolean; | ||
| isFollow: boolean | null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Search for all isFollow usage in the codebase
rg -nP --type=ts --type=tsx '\.isFollow\b' -g '!*.test.*' -g '!*.spec.*' -g '!node_modules'Repository: WeGo-Together/WeGo_FrontEnd Length of output: 98 🏁 Script executed: # Check the type definition file and related files
cat -n src/types/service/user.tsRepository: WeGo-Together/WeGo_FrontEnd Length of output: 1424 🏁 Script executed: # Search for isFollow in condition checks to see how it's being handled
rg -nP --type=ts --type=tsx 'isFollow\s*(===|!==|==|!=|\?|!)' -g '!*.test.*' -g '!*.spec.*' -g '!node_modules'Repository: WeGo-Together/WeGo_FrontEnd Length of output: 98 🏁 Script executed: # Search for isFollow usage without specifying tsx
rg -nP '\.isFollow\b' -g '!*.test.*' -g '!*.spec.*' -g '!node_modules' | head -50Repository: WeGo-Together/WeGo_FrontEnd Length of output: 840 🏁 Script executed: # Search for isFollow in condition checks
rg -nP 'isFollow\s*(===|!==|==|!=|\?|!)' -g '!*.test.*' -g '!*.spec.*' -g '!node_modules'Repository: WeGo-Together/WeGo_FrontEnd Length of output: 616 🏁 Script executed: # Look at profile-related files that handle isFollow
fd -e ts -e js -e jsx -e tsx 'profile' | grep -v node_modules | grep -v test | head -20Repository: WeGo-Together/WeGo_FrontEnd Length of output: 53 🏁 Script executed: # Check the mock handler mentioned in learnings
cat -n src/mock/service/user/user-handler.ts | head -50Repository: WeGo-Together/WeGo_FrontEnd Length of output: 1748 🏁 Script executed: # Check the profile-info component in detail to understand the logic
cat -n src/components/pages/user/profile/profile-info/index.tsx | sed -n '25,40p'Repository: WeGo-Together/WeGo_FrontEnd Length of output: 589 🏁 Script executed: # Verify if there are any other isFollow usages we missed
rg 'isFollow' -g '!*.test.*' -g '!*.spec.*' -g '!node_modules' --count-matchesRepository: WeGo-Together/WeGo_FrontEnd Length of output: 279 🏁 Script executed: # Check the actual user mock data to see what values are set
fd 'user-mock' | xargs cat -n | head -60Repository: WeGo-Together/WeGo_FrontEnd Length of output: 2063 프로필 정보 컴포넌트에 명시적 null 방어 로직 추가 필요
현재는 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| export interface GetUserPathParams { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이게 뭔가용?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next.js는 기본적으로 빌드할 때 SSG가 되므로 prerendering을 하는데, users/me api가 기본적으로 token이 필요한 api라 빌드 시점에 렌더링이 되지 않는 문제가 있어요
그래서 이걸 추가해주면 prerendering을 하지 않게 됩니다!
단점은 SEO 적용이 어렵다는 점이 있는데, 어차피 권한이 필요한 페이지라 상관이 없어서 추가했어요 :)