-
Notifications
You must be signed in to change notification settings - Fork 5
Fix(client): User query 통합 및 게시글 수정 페이지 권한 가드 #505
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
96df632
56d21dd
b603c39
580ff43
8fc054d
500ebba
4d576bf
38fca40
cf6a4b8
12abd77
e9a7c8d
fc6f3b6
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 |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { LoaderFunctionArgs, redirect } from 'react-router'; | ||
|
|
||
| import { isPostAuthor } from '@widgets/community/utils/is-post-author'; | ||
|
|
||
| import { COMMUNITY_QUERY_OPTIONS } from '@shared/api/domain/community/queries'; | ||
| import { USER_QUERY_OPTIONS } from '@shared/api/domain/queries'; | ||
| import { routePath } from '@shared/router/path'; | ||
| import { queryClient } from '@shared/utils/query-client'; | ||
|
|
||
| export const communityEditLoader = async ({ params }: LoaderFunctionArgs) => { | ||
|
Member
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. 오오오 LoaderFunctionArgs 이런것도 있군요... react router loader 함수가 받는 params 인자 타입을 정의해주는 기능 처음 알아갑니다 !! |
||
| const postId = params.postId; | ||
|
|
||
| if (!postId) { | ||
| throw new Error('글 수정 페이지에서 postId를 찾을 수 없습니다.'); | ||
| } | ||
|
|
||
| const [feedDetailData, userData] = await Promise.all([ | ||
| queryClient.ensureQueryData(COMMUNITY_QUERY_OPTIONS.FEED_DETAIL(postId)), | ||
| queryClient.ensureQueryData(USER_QUERY_OPTIONS.PROFILE()), | ||
| ]); | ||
|
Comment on lines
+17
to
+20
Member
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. Promise.all을 쓰신 이유가 두개의 요청을 동시에 시작하기 위해서인가요? 만약에 한쪽 요청이 실패했을 때 전체 loader가 실패하는 동작도 의도하신 걸까요? JW입니당..
Member
Author
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.
네 맞아요! 두 쿼리를 Promise.all 없이 사용하면 FEED_DETAIL 먼저 받아오고 PROFILE을 받아오니 순차적으로 호출하면 시간이 더 딜레이 될것 같아요. 어차피 독립적인 요청이니 한번에 처리한게 맞습니다 |
||
|
|
||
| if (!isPostAuthor(feedDetailData?.writerId, userData?.data?.userId)) { | ||
| return redirect(routePath.COMMUNITY_DETAIL.replace(':postId', postId)); | ||
| } | ||
|
|
||
| return null; | ||
| }; | ||
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.
제가 말한 loader 는 createBrowserRouter 레벨에 있는 React Router 에 loader 에용
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.
createBrowserRouter 아래 protectedRoutes 안의 community-edit 라우트에 loader를 연결해서 페이지 컴포넌트 렌더 전에 작성자 권한을 확인하도록 구현했는데 지욱님이 말씀하시는건 community-edit과 같은 개별 라우트 레벨이 아니라 createBrowserRouter에서 ProtectedRoute가 있는 상위 route 객체 레벨에 loader를 두는 방향인가욥??
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.
추가로 작성자 권한 체크는 현재 기준으로 community-edit 라우트에서만 사용되고 있어서 우선은 상위 라우트 레벨이 아니라 community-edit 개별 라우트의 loader에서 처리 하는게 좋을것 같다고 생각했었어요!
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.
맞는 것 같아요 depth 가 추가로 들어가는 구조 자체가 좀 불편하긴한데 지금 상황에선 이렇게 구현 하는게 맞을 것 같아용