Skip to content

Commit

Permalink
feat : 페이지별 권한 추가
Browse files Browse the repository at this point in the history
- NeedAuth는 회장과 부회장은 무조건 허용하도록 수정
- #888
  • Loading branch information
jasper200207 committed Mar 26, 2024
1 parent 39d4844 commit cae9db2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/components/NeedAuth/NeedAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import ConfirmModal from '@components/Modal/ConfirmModal';

interface NeedLoginProps {
children: JSX.Element;
roles: Role[];
roles?: Role[];
}

const NeedAuth = ({ children, roles }: NeedLoginProps) => {
const NeedAuth = ({ children, roles = [] }: NeedLoginProps) => {
const { checkIncludeOneOfAuths } = useCheckAuth();
const navigate = useNavigate();

const onClose = () => {
navigate('/');
};

if (checkIncludeOneOfAuths(roles)) {
if (checkIncludeOneOfAuths([...roles, 'ROLE_회장', 'ROLE_부회장'])) {
return children;
}
return (
Expand Down
86 changes: 72 additions & 14 deletions src/router/useMainRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import SeminarAttend from '@pages/senimarAttend/SenimarAttend';
import FitContainer from '@components/Layout/Container/FitContainer';
import FullContainer from '@components/Layout/Container/FullContainer';
import MainLayout from '@components/Layout/MainLayout';
import NeedAuth from '@components/NeedAuth/NeedAuth';
import NeedLogin from '@components/NeedAuth/NeedLogin';

const useMainRouter = () =>
useRoutes([
Expand Down Expand Up @@ -54,7 +56,11 @@ const useMainRouter = () =>
},
{
path: 'profile/:memberId/*',
element: <Profile />,
element: (
<NeedLogin>
<Profile />
</NeedLogin>
),
},
],
},
Expand All @@ -66,27 +72,47 @@ const useMainRouter = () =>
children: [
{
path: 'dutyManage',
element: <DutyManage />,
element: (
<NeedAuth>
<DutyManage />
</NeedAuth>
),
},
/* {
path: 'electionManage',
element: <div />,
}, */
{
path: 'libraryManage/*',
element: <LibraryManage />,
element: (
<NeedAuth roles={['ROLE_사서']}>
<LibraryManage />
</NeedAuth>
),
},
{
path: 'seminarManage',
element: <SeminarManage />,
element: (
<NeedAuth roles={['ROLE_서기']}>
<SeminarManage />
</NeedAuth>
),
},
{
path: 'activeMemberManage',
element: <ActiveMemberManage />,
element: (
<NeedAuth roles={['ROLE_서기']}>
<ActiveMemberManage />
</NeedAuth>
),
},
{
path: 'meritManage',
element: <MeritManage />,
element: (
<NeedAuth roles={['ROLE_서기']}>
<MeritManage />
</NeedAuth>
),
},
],
},
Expand All @@ -95,41 +121,73 @@ const useMainRouter = () =>
children: [
{
path: ':categoryName',
element: <BoardList />,
element: (
<NeedLogin>
<BoardList />
</NeedLogin>
),
},
{
path: 'write/:categoryName',
element: <BoardWrite />,
element: (
<NeedLogin>
<BoardWrite />
</NeedLogin>
),
},
{
path: 'view/:postId',
element: <BoardView />,
element: (
<NeedLogin>
<BoardView />
</NeedLogin>
),
},
],
},
{
path: 'study',
element: <Study />,
element: (
<NeedLogin>
<Study />
</NeedLogin>
),
},
{
path: 'library',
element: <Library />,
element: (
<NeedLogin>
<Library />
</NeedLogin>
),
},
{
path: 'seminar',
element: <SeminarAttend />,
element: (
<NeedLogin>
<SeminarAttend />
</NeedLogin>
),
},
/* {
path: 'election',
element: <div />,
}, */
{
path: 'rank',
element: <Rank />,
element: (
<NeedLogin>
<Rank />
</NeedLogin>
),
},
{
path: 'game',
element: <Game />,
element: (
<NeedLogin>
<Game />
</NeedLogin>
),
},
/* {
path: 'ctf',
Expand Down

0 comments on commit cae9db2

Please sign in to comment.