Skip to content

Commit

Permalink
Merge pull request #135 from jeiltodo/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Dragonite-Lee authored Aug 28, 2024
2 parents fdd2071 + f6df525 commit f94fe46
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 72 deletions.
2 changes: 1 addition & 1 deletion apps/admin/src/app/(dashboard)/group/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TableProvider } from '../../../../shared';
export default function Page() {
return (
<TableProvider>
<GroupManagementDetailPage />;
<GroupManagementDetailPage />
</TableProvider>
);
}
2 changes: 1 addition & 1 deletion apps/admin/src/app/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';

const Loading = () => {
return (
<div className='relative'>
<div className='relative w-screen h-screen'>
<LoadingSpinner />
</div>
);
Expand Down
14 changes: 12 additions & 2 deletions apps/admin/src/app/style/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@
.swiper-button-next {
position: absolute;
top: 50%;
width: 40px !important;
height: 40px;
width: 50px !important;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
z-index: 50;
font-weight: bold !important;
color: #1e293b !important;
}

.swiper-button-prev {
Expand All @@ -71,3 +73,11 @@
.swiper-button-next::after {
font-size: 24px !important;
}

.swiper-pagination {
bottom: -20% !important;
}

.swiper-pagination-bullet.swiper-pagination-bullet-active {
background-color: #1e293b !important;
}
39 changes: 30 additions & 9 deletions apps/admin/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';

// 관리자 보호 경로 목록 (basePath 적용)
const protectedAdminRoutes = [
'/',
'/goals',
'/group',
'/members',
];

// 관리자 공개 경로 목록 (basePath 적용)
const publicAdminRoutes = ['/login'];

export function middleware(request: NextRequest) {
const token = request.cookies.get('accessAdminToken')?.value;
const path = request.nextUrl.pathname;

console.log('path: ', path);
console.log('관리자 Middleware running');
console.log('관리자 Middleware running');
console.log('Request URL:', request.nextUrl.pathname);
console.log('Request URL:', path);
console.log('Token:', token);
if (request?.nextUrl.pathname === '/admin') {
console.log('토큰있나요? ', token);

// 보호된 관리자 경로에 접근 시 토큰 체크
if (protectedAdminRoutes.some(route => path === route || path.startsWith(`${route}/`))) {
if (!token) {
console.log('Redirecting to /login');
console.log('Redirecting to /admin/login');
return NextResponse.redirect(new URL('/admin/login', request.url));
}
console.log('Token is present, proceeding...');
}
if (request?.nextUrl.pathname === '/admin/login') {

// 로그인한 관리자가 로그인 페이지에 접근하려 할 때 관리자 대시보드로 리다이렉트
if (publicAdminRoutes.some(route => path === route || path.startsWith(`${route}/`))) {
if (token) {
console.log('Redirecting to /');
return NextResponse.redirect(new URL('/admin', request.url));
console.log('Redirecting to /admin');
// return NextResponse.redirect(new URL('/admin', request.url));
}
}

// 다른 모든 경로에 대해서는 그대로 진행
return NextResponse.next();
}

export const config = {
matcher: ['/:path*'],
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|logo.png|s-logo.png).*)'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const PostsIndividualPage = () => {
)}
</TableCheckListProvider>
<TablePagination
totalCount={data.totalCount}
totalCount={data.searchedCount}
currentPage={data.currentPage}
/>
</div>
Expand Down
12 changes: 10 additions & 2 deletions apps/admin/src/page/members/ui/member-management-page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { LayoutTitle, LoadingSpinner } from '@jeiltodo/ui/shared';
import { LayoutTitle, LoadingSpinner, useToast } from '@jeiltodo/ui/shared';
import { MembersTable } from '../../../widgets/members/ui/members-table';
import {
SearchFilter,
Expand All @@ -17,6 +17,7 @@ import { TableCheckListProvider } from '../../../shared/model/table/table-checkl
import { useDeleteMembers } from '../../../entities/member/hooks/useDeleteMembers';

export const MemberManagementPage = () => {
const showToast = useToast();
const { tableFilters, tableSort } = useTableContext();
const { data, isLoading } = useGetMembers(tableFilters);
const { mutate: deleteMembers } = useDeleteMembers();
Expand All @@ -29,7 +30,14 @@ export const MemberManagementPage = () => {
}, [data?.members, tableSort]);

const handleDelete = (ids: number[]) => {
deleteMembers(ids);
if (ids.length === 0) {
showToast({
message: '체크된 항목이 없습니다.',
type: 'confirm',
});
} else {
deleteMembers(ids);
}
};

if (isLoading || !data || !data.members) return <LoadingSpinner />;
Expand Down
2 changes: 1 addition & 1 deletion apps/user/src/app/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';

const Loading = () => {
return (
<div className='relative'>
<div className='relative w-screen h-screen'>
<LoadingSpinner />
</div>
);
Expand Down
14 changes: 12 additions & 2 deletions apps/user/src/app/style/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@
.swiper-button-next {
position: absolute;
top: 50%;
width: 40px !important;
height: 40px;
width: 50px !important;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
z-index: 50;
font-weight: bold !important;
color: #1e293b !important;
}

.swiper-button-prev {
Expand All @@ -70,3 +72,11 @@
.swiper-button-next::after {
font-size: 24px !important;
}

.swiper-pagination {
bottom: -20% !important;
}

.swiper-pagination-bullet.swiper-pagination-bullet-active {
background-color: #1e293b !important;
}
27 changes: 21 additions & 6 deletions apps/user/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';

// 보호된 경로 목록
const protectedRoutes = ['/', '/goal', '/group', '/note', '/todo'];

// 공개 경로 목록 (로그인하지 않아도 접근 가능한 경로)
const publicRoutes = ['/login', '/signup'];

export function middleware(request: NextRequest) {
const token = request.cookies.get('accessToken')?.value;

console.log('유저 Middleware running');
console.log('Request URL:', request.nextUrl.pathname);
console.log('Token:', token);

// 로그인을 하지 않아 토큰이 없으면 login페이지로 리다이렉트
if (request.nextUrl.pathname === '/') {
const path = request.nextUrl.pathname;

// 보호된 경로에 접근하려 할 때 토큰이 없으면 로그인 페이지로 리다이렉트
if (
protectedRoutes.some(
(route) => path === route || path.startsWith(`${route}/`)
)
) {
if (!token) {
console.log('Redirecting to /login');
return NextResponse.redirect(new URL('/login', request.url));
}
}

//로그인을 해서 토큰이 있으면 login페이지로 못가도록 홈페이지로 리다이렉트
if (request.nextUrl.pathname === '/login') {
// 이미 로그인한 사용자가 로그인 또는 회원가입 페이지에 접근하려 할 때 홈페이지로 리다이렉트
if (publicRoutes.includes(path)) {
if (token) {
console.log('Redirecting to /');
return NextResponse.redirect(new URL('/', request.url));
}
}

// 다른 모든 경로에 대해서는 그대로 진행
return NextResponse.next();
}

//특정 path로만 해당 미들웨어가 동작
// 모든 경로에 대해 미들웨어 적용
export const config = {
matcher: ['/:path*'],
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};
1 change: 1 addition & 0 deletions packages/config-tailwind/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const config: Omit<Config, 'content'> = {
modal_sm: '640px',
desktop: '1024px',
'max-tablet': { max: '480px' },
'desktop-2xl': '1220px',
},

extend: {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/entities/group/ui/group-overview-board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const GroupOverviewBoard = ({
return (
<BoardLayout
title='그룹 정보'
className={isAdmin ? 'w-[400px]' : 'tablet:min-w-[400px]'}
className={isAdmin ? 'w-[400px]' : 'tablet:min-w-[300px]'}
isAdmin={isAdmin}
>
<div
Expand Down
10 changes: 3 additions & 7 deletions packages/ui/src/entities/group/ui/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const Profile = ({
onClickRemove,
}: ProfileProps) => {
return (
<div className={`relative w-fit pt-6`}>
<div className={`flex flex-col items-center w-20 pt-6`}>
{isLeader === true && mode !== 'change-leader' && (
<span className='absolute top-[-4px] inline-block w-full text-center font-semibold text-sm text-white'>
그룹장
Expand Down Expand Up @@ -57,11 +57,7 @@ export const Profile = ({
<MemberHat width={38} className='absolute top-[12px] left-[14px]' />
</div>
{contributionRank === RANK_LOWEST && (
<AvatarRags
width={12}
height={16}
className='absolute w-3 h-4 top-[12px] right-[14px]'
/>
<AvatarRags width={64} height={64} className='absolute inset-0' />
)}
{contributionRank === RANK_HIGHST && (
<AvatarSunglasses
Expand All @@ -71,7 +67,7 @@ export const Profile = ({
/>
)}
</div>
<span className='inline-block w-full text-center font-semibold text-sm text-white mt-2'>
<span className='inline-block w-full text-clip text-center font-semibold text-sm text-white mt-2'>
{nickname}
</span>
</div>
Expand Down
10 changes: 4 additions & 6 deletions packages/ui/src/entities/user/hooks/useUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ export const useLogoutMutation = (admin = false) => {
mutationFn: (data: LogoutData) => userApi.logoutUserInfo(data, admin),
onSuccess: () => {
queryClient.clear(); // 모든 쿼리 캐시를 지웁니다.
deleteCookie('accessToken');
deleteCookie('refreshToken');

window.location.reload();
deleteCookie(admin ? 'accessAdminToken' : 'accessToken');
deleteCookie(admin ? 'refreshAdminToken' : 'refreshToken');
},
onError: (error: Error) => {
showToast({ message: '로그아웃에 실패했습니다.', type: 'confirm' });
Expand All @@ -52,8 +50,8 @@ export const useWithdrawMutation = (admin = false) => {
mutationFn: () => userApi.withdrawUserInfo(admin),
onSuccess: () => {
queryClient.clear(); // 모든 쿼리 캐시를 지웁니다.
deleteCookie('accessToken');
deleteCookie('refreshToken');
deleteCookie(admin ? 'accessAdminToken' : 'accessToken');
deleteCookie(admin ? 'refreshAdminToken' : 'refreshToken');
},
onError: (error: Error) => {
showToast({ message: '회원 탈퇴에 실패했습니다.', type: 'confirm' });
Expand Down
17 changes: 14 additions & 3 deletions packages/ui/src/entities/user/ui/user-info-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ import {
useWithdrawMutation,
} from '../../../entities/user/hooks/useUser';
import {
ACCESS_ADMIN_TOKEN_COOKIE_NAME,
ACCESS_TOKEN_COOKIE_NAME,
REFRESH_ADMIN_TOKEN_COOKIE_NAME,
REFRESH_TOKEN_COOKIE_NAME,
} from '../../../shared/config/token';
import { useRouter } from 'next/navigation';

interface Props {
userInfo: UserDataprops | undefined;
Expand All @@ -41,10 +44,16 @@ export const UserInfoModal = ({
const debouncedEmail = useDebounce(email, 1000);

const tokenData = {
accessToken: getCookie(ACCESS_TOKEN_COOKIE_NAME),
refreshToken: getCookie(REFRESH_TOKEN_COOKIE_NAME),
accessToken: isAdmin
? getCookie(ACCESS_ADMIN_TOKEN_COOKIE_NAME)
: getCookie(ACCESS_TOKEN_COOKIE_NAME),
refreshToken: isAdmin
? getCookie(REFRESH_ADMIN_TOKEN_COOKIE_NAME)
: getCookie(REFRESH_TOKEN_COOKIE_NAME),
};

const router = useRouter();

const updateUserMutation = useUpdateUserInfoMutation(isAdmin);
const logoutMutation = useLogoutMutation(isAdmin);
const withdrawMutation = useWithdrawMutation(isAdmin);
Expand Down Expand Up @@ -97,16 +106,18 @@ export const UserInfoModal = ({

const handleLogout = () => {
logoutMutation.mutate(tokenData);
router.push('/login');
};

const handleWithdraw = () => {
withdrawMutation.mutate();
router.push('/login');
};

useEffect(() => {
setNickname(userInfo?.nickname || '');
setEmail(userInfo?.email || '');
}, [userInfo])
}, [userInfo]);

return (
<BaseModal
Expand Down
Loading

0 comments on commit f94fe46

Please sign in to comment.