@@ -3,6 +3,7 @@ import { notFound, redirect } from 'next/navigation';
33import { dehydrate , HydrationBoundary } from '@tanstack/react-query' ;
44
55import { API } from '@/api' ;
6+ import { generateProfileMetadata } from '@/lib/metadata/profile' ;
67import { getQueryClient } from '@/lib/query-client' ;
78import { userKeys } from '@/lib/query-key/query-key-user' ;
89
@@ -11,6 +12,12 @@ interface Props {
1112 params : Promise < { userId : string } > ;
1213}
1314
15+ export const generateMetadata = async ( { params } : Props ) => {
16+ const { userId : id } = await params ;
17+ const userId = Number ( id ) ;
18+ return await generateProfileMetadata ( userId ) ;
19+ } ;
20+
1421const ProfileLayout = async ( { children, params } : Props ) => {
1522 const { userId : id } = await params ;
1623 const userId = Number ( id ) ;
@@ -20,13 +27,22 @@ const ProfileLayout = async ({ children, params }: Props) => {
2027
2128 const queryClient = getQueryClient ( ) ;
2229
23- const user = await queryClient . fetchQuery ( {
24- queryKey : userKeys . item ( userId ) ,
25- queryFn : ( ) => API . userService . getUser ( { userId } ) ,
26- } ) ;
27-
28- // isFollow가 null이면 본인 페이지 이므로 mypage로 redirect 처리
29- if ( user . isFollow === null ) redirect ( '/mypage' ) ;
30+ const [ user , me ] = await Promise . all ( [
31+ queryClient . fetchQuery ( {
32+ queryKey : userKeys . item ( userId ) ,
33+ queryFn : ( ) => API . userService . getUser ( { userId } ) ,
34+ } ) ,
35+ queryClient
36+ . fetchQuery ( {
37+ queryKey : userKeys . me ( ) ,
38+ queryFn : ( ) => API . userService . getMeSkipRedirect ( ) ,
39+ } )
40+ . catch ( ( ) => null ) ,
41+ ] ) ;
42+
43+ if ( ! user ) notFound ( ) ;
44+
45+ if ( me ?. userId === user . userId ) redirect ( '/mypage' ) ;
3046
3147 return < HydrationBoundary state = { dehydrate ( queryClient ) } > { children } </ HydrationBoundary > ;
3248} ;
0 commit comments