Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Walkthrough이 변경 사항은 애플리케이션의 역할(role) 관리 체계를 재설계합니다. 기존의 JWT 파싱과 토큰 기반 역할 검증을 제거하고, 새로운
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
apps/web/src/components/mentor/MentorExpandChatCard/hooks/useExpandCardClickHandler.ts (1)
28-40: 중복된!isCheckedState조건문Lines 30-32와 33-39에서
!isCheckedState조건을 두 번 체크하고 있습니다. 이를 하나로 합칠 수 있습니다.♻️ 조건문 통합 제안
const handleExpandClick = () => { setIsExpanded(!isExpanded); - if (!isCheckedState) { - setIsCheckedState(true); - } - if (!isCheckedState) { + if (!isCheckedState && clientRole) { + setIsCheckedState(true); if (isMentor) { patchCheckMentorings({ checkedMentoringIds: [mentoringId] }); } else { patchMenteeCheckMentorings({ checkedMentoringIds: [mentoringId] }); } } };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/src/components/mentor/MentorExpandChatCard/hooks/useExpandCardClickHandler.ts` around lines 28 - 40, The handleExpandClick function currently checks !isCheckedState twice; refactor by toggling expansion with setIsExpanded(!isExpanded) then, in a single if (!isCheckedState) block call setIsCheckedState(true) and invoke the appropriate API: if (isMentor) call patchCheckMentorings({ checkedMentoringIds: [mentoringId] }) else call patchMenteeCheckMentorings({ checkedMentoringIds: [mentoringId] }); keep the same referenced symbols (handleExpandClick, setIsExpanded, setIsCheckedState, isCheckedState, isMentor, patchCheckMentorings, patchMenteeCheckMentorings, mentoringId).apps/web/src/lib/zustand/useAuthStore.ts (1)
92-100: 2.setClientRole가드 로직 - 빈 객체 반환 시 무음 실패
serverRole !== ADMIN일 때 빈 객체{}를 반환하여 상태 변경 없이 조용히 무시됩니다. 이는 의도된 동작이지만, 디버깅 시 혼란을 줄 수 있습니다.개발 환경에서 경고 로그를 추가하는 것을 고려해보세요:
💡 디버깅 편의를 위한 경고 로그 추가 제안
setClientRole: (role) => { set((state) => { if (state.serverRole !== UserRole.ADMIN) { + if (process.env.NODE_ENV === "development") { + console.warn("[useAuthStore] setClientRole called but serverRole is not ADMIN"); + } return {}; } return { clientRole: role }; }); },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/src/lib/zustand/useAuthStore.ts` around lines 92 - 100, The setClientRole updater silently ignores attempts when state.serverRole !== UserRole.ADMIN by returning an empty object; change it to emit a dev-only warning so unauthorized attempts are visible: inside setClientRole (the function using set and checking state.serverRole), detect the non-ADMIN case and call a logger (e.g., console.warn or your app logger) with a clear message including the attempted role and current serverRole, then return the unchanged state as before; ensure the warning runs only in development (process.env.NODE_ENV !== 'production') to avoid noisy logs in production.apps/web/src/components/layout/GlobalLayout/ui/AIInspectorFab/index.tsx (1)
22-22: 페이지 이동 시 메뉴 상태 초기화 고려
isMenuOpen상태가 페이지 이동 후에도 유지될 수 있습니다. SPA 특성상 컴포넌트가 언마운트되지 않으면 메뉴가 열린 채로 남을 수 있습니다.필요시 라우트 변경 감지하여 메뉴를 닫는 로직을 추가할 수 있습니다.
💡 라우트 변경 시 메뉴 닫기 (선택적)
import { usePathname } from "next/navigation"; import { useEffect } from "react"; // 컴포넌트 내부에서 const pathname = usePathname(); useEffect(() => { setIsMenuOpen(false); }, [pathname]);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/src/components/layout/GlobalLayout/ui/AIInspectorFab/index.tsx` at line 22, isMenuOpen can persist across SPA route changes; add route-change detection to automatically close the menu by using Next's usePathname and a useEffect that calls setIsMenuOpen(false) whenever pathname changes (inside the AIInspectorFab component where isMenuOpen and setIsMenuOpen are defined). Import usePathname and useEffect, derive const pathname = usePathname(), and add useEffect(() => setIsMenuOpen(false), [pathname]) to reset the menu on navigation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@apps/web/src/components/mentor/MentorExpandChatCard/hooks/useExpandCardClickHandler.ts`:
- Around line 20-21: The hook useExpandCardClickHandler currently computes
isMentor from clientRole which can be null; add a defensive guard so that when
clientRole is null you do not proceed to mentor-only logic or call
patchMenteeCheckMentorings. Specifically, update the handler in
useExpandCardClickHandler to check if clientRole == null (or undefined) and
short-circuit/return (or skip mentor branch) before evaluating isMentor or
invoking patchMenteeCheckMentorings, ensuring mentor-only API calls run only
when clientRole is a non-null UserRole value.
---
Nitpick comments:
In `@apps/web/src/components/layout/GlobalLayout/ui/AIInspectorFab/index.tsx`:
- Line 22: isMenuOpen can persist across SPA route changes; add route-change
detection to automatically close the menu by using Next's usePathname and a
useEffect that calls setIsMenuOpen(false) whenever pathname changes (inside the
AIInspectorFab component where isMenuOpen and setIsMenuOpen are defined). Import
usePathname and useEffect, derive const pathname = usePathname(), and add
useEffect(() => setIsMenuOpen(false), [pathname]) to reset the menu on
navigation.
In
`@apps/web/src/components/mentor/MentorExpandChatCard/hooks/useExpandCardClickHandler.ts`:
- Around line 28-40: The handleExpandClick function currently checks
!isCheckedState twice; refactor by toggling expansion with
setIsExpanded(!isExpanded) then, in a single if (!isCheckedState) block call
setIsCheckedState(true) and invoke the appropriate API: if (isMentor) call
patchCheckMentorings({ checkedMentoringIds: [mentoringId] }) else call
patchMenteeCheckMentorings({ checkedMentoringIds: [mentoringId] }); keep the
same referenced symbols (handleExpandClick, setIsExpanded, setIsCheckedState,
isCheckedState, isMentor, patchCheckMentorings, patchMenteeCheckMentorings,
mentoringId).
In `@apps/web/src/lib/zustand/useAuthStore.ts`:
- Around line 92-100: The setClientRole updater silently ignores attempts when
state.serverRole !== UserRole.ADMIN by returning an empty object; change it to
emit a dev-only warning so unauthorized attempts are visible: inside
setClientRole (the function using set and checking state.serverRole), detect the
non-ADMIN case and call a logger (e.g., console.warn or your app logger) with a
clear message including the attempted role and current serverRole, then return
the unchanged state as before; ensure the warning runs only in development
(process.env.NODE_ENV !== 'production') to avoid noisy logs in production.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 7c52b6ca-d8eb-457e-9f8f-f319b986b7c0
📒 Files selected for processing (7)
apps/web/src/app/mentor/_ui/MentorClient/index.tsxapps/web/src/app/my/_ui/MyProfileContent/index.tsxapps/web/src/app/my/match/_ui/MatchContent/index.tsxapps/web/src/components/layout/GlobalLayout/ui/AIInspectorFab/index.tsxapps/web/src/components/mentor/MentorApplyCountContent/index.tsxapps/web/src/components/mentor/MentorExpandChatCard/hooks/useExpandCardClickHandler.tsapps/web/src/lib/zustand/useAuthStore.ts
| const clientRole = useAuthStore((state) => state.clientRole); | ||
| const isMentor = clientRole === UserRole.MENTOR; |
There was a problem hiding this comment.
clientRole이 null일 때의 엣지 케이스
clientRole이 null인 경우 (초기화 중 또는 토큰 만료 시):
isMentor = null === UserRole.MENTOR→false- 멘토 사용자가 잘못된 API(
patchMenteeCheckMentorings)를 호출할 수 있습니다
이 훅을 사용하는 MentorExpandChatCard는 인증된 페이지 내에서 렌더링되지만, 방어적 코딩으로 clientRole이 null일 때 API 호출을 건너뛰는 것이 안전합니다.
🛡️ 방어적 가드 추가 제안
const handleExpandClick = () => {
setIsExpanded(!isExpanded);
if (!isCheckedState) {
setIsCheckedState(true);
}
- if (!isCheckedState) {
+ if (!isCheckedState && clientRole) {
if (isMentor) {
patchCheckMentorings({ checkedMentoringIds: [mentoringId] });
} else {
patchMenteeCheckMentorings({ checkedMentoringIds: [mentoringId] });
}
}
};🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@apps/web/src/components/mentor/MentorExpandChatCard/hooks/useExpandCardClickHandler.ts`
around lines 20 - 21, The hook useExpandCardClickHandler currently computes
isMentor from clientRole which can be null; add a defensive guard so that when
clientRole is null you do not proceed to mentor-only logic or call
patchMenteeCheckMentorings. Specifically, update the handler in
useExpandCardClickHandler to check if clientRole == null (or undefined) and
short-circuit/return (or skip mentor branch) before evaluating isMentor or
invoking patchMenteeCheckMentorings, ensuring mentor-only API calls run only
when clientRole is a non-null UserRole value.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b6f2dd6a04
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return { | ||
| accessToken: token, | ||
| serverRole, | ||
| clientRole: resolveClientRole(serverRole, state.clientRole), |
There was a problem hiding this comment.
Default admin clientRole on token role change
setAccessToken always reuses state.clientRole when the new token is for an admin, so switching accounts from a mentee session to an admin session without an explicit clearAccessToken keeps clientRole as MENTEE. Login mutations call setAccessToken directly, so this path is reachable and makes first admin render open in mentee UI instead of the intended default mentor UI.
Useful? React with 👍 / 👎.
관련 이슈
작업 내용
serverRole(권한 판정용)과clientRole(UI 뷰 판정용)로 분리했습니다.clientRole기준으로, admin 여부/플로팅 버튼 노출은serverRole기준으로 동작하도록 분리했습니다.serverRole) 기준으로 유지하고, 카드 확장 읽음 처리 분기는 UI 역할(clientRole) 기준으로 맞췄습니다.특이 사항
setAccessToken/rehydrate 시 admin의clientRole은 기존 선택값을 유지하고, 최초에는 멘토 뷰를 기본값으로 설정했습니다.serverRole/clientRole을 함께 초기화합니다.리뷰 요구사항 (선택)
멘티 UI 보기로 전환해도 좌하단 플로팅 버튼(관리 메뉴)이 계속 노출되는지 확인 부탁드립니다./my), 매칭(/my/match), 멘토(/mentor)에서 기존 상단 토글이 완전히 제거되었는지 확인 부탁드립니다.