260508_17_ENH: 클라이언트 강력 요청으로 로그인 아예 걷고 파라미터 기반으로 admin 기능 우회

This commit is contained in:
2026-05-08 12:16:35 +09:00
parent fc1074cf4e
commit f37e2923e9
4 changed files with 39 additions and 31 deletions

View File

@@ -1,13 +1,13 @@
"use client";
import { useEffect, useMemo, useState } from "react";
import { useSearchParams } from "next/navigation";
import { useQueryClient } from "@tanstack/react-query";
import { toast } from "sonner";
import DataTable from "@/components/table/DataTable";
import type { DataColumn } from "@/components/table/types";
import { Button } from "@/components/ui/button";
import { DIV_KEY_MAP } from "@/config/kfpaConfig";
import { useAuth } from "@/hooks/useAuth";
import { formatKoreanBaseDate } from "@/lib/utils";
import { useWriteDivCommentMutation } from "@/query/admin";
import { statisticsQueryKeys } from "@/query/key/keys";
@@ -15,6 +15,7 @@ import { useDivDetailDataQuery } from "@/query/statistics";
import type { CommentValue, DivDetailData } from "@/types/kfpa";
import { Pencil, Save, X } from 'lucide-react';
import SectionTitle from "@/components/common/SectionTitle";
import { hasAdminRouteParam } from "@/lib/admin-route";
export type SafetyInspectionDivDetailProps = {
selectedDiv: string;
@@ -85,7 +86,7 @@ const createDraft = (columns: Array<{ key: string }>, source?: Record<string, Co
}, {});
const SafetyInspectionDivDetail = ({ selectedDiv }: SafetyInspectionDivDetailProps) => {
const { auth } = useAuth();
const searchParams = useSearchParams();
const queryClient = useQueryClient();
const { data, isLoading, isError } = useDivDetailDataQuery(selectedDiv, selectedDiv !== "-1");
const writeMutation = useWriteDivCommentMutation();
@@ -103,7 +104,7 @@ const SafetyInspectionDivDetail = ({ selectedDiv }: SafetyInspectionDivDetailPro
}, [commentColumns, detail?.commentValues, selectedDiv]);
const baseDateLabel = useMemo(() => formatKoreanBaseDate(), []);
const isAuthenticated = auth.user != null;
const isAuthenticated = hasAdminRouteParam(searchParams);
const rankRows: RankRow[] = useMemo(() => {
const ranks = detail?.csiRanks ?? {};

View File

@@ -69,27 +69,31 @@ const Header = ({
<h1 className="font-bold content-text-2xl text-header-color">{SITE_TITLE}</h1>
</div>
<div className="flex min-w-0 items-center justify-end gap-4">
{isAuthenticated && (
<span className="content-text-base text-header-color hidden max-w-40 truncate sm:inline font-bold">
{userName}
</span>
)}
<Button
className="gap-2 border border-transparent bg-green-600 text-white w-25 shadow-sm hover:bg-green-500 hover:text-white"
onClick={isAuthenticated ? onLogout : onLogin}
>
{isAuthenticated ? (
<>
<LogOut className="w-4 h-4" />
<span className="hidden sm:inline">{"로그아웃"}</span>
</>
) : (
<>
<LogIn className="w-4 h-4" />
<span className="hidden sm:inline">{"로그인"}</span>
</>
{
/* 클라이언트 요청으로 로그인 제외
{isAuthenticated && (
<span className="content-text-base text-header-color hidden max-w-40 truncate sm:inline font-bold">
{userName}
</span>
)}
</Button>
<Button
className="gap-2 border border-transparent bg-green-600 text-white w-25 shadow-sm hover:bg-green-500 hover:text-white"
onClick={isAuthenticated ? onLogout : onLogin}
>
{isAuthenticated ? (
<>
<LogOut className="w-4 h-4" />
<span className="hidden sm:inline">{"관리자 로그아웃"}</span>
</>
) : (
<>
<LogIn className="w-4 h-4" />
<span className="hidden sm:inline">{"관리자 로그인"}</span>
</>
)}
</Button>
*/
}
</div>
</div>
</header>

View File

@@ -1,7 +1,7 @@
"use client"
import {ReactNode, useEffect, useState} from "react";
import {useRouter} from "next/navigation";
import {useRouter, useSearchParams} from "next/navigation";
import {DivKey} from "@/types/kfpa";
import {useAuth} from "@/hooks/useAuth";
import {LayoutCategoryProvider} from "./LayoutCategoryContext";
@@ -12,6 +12,7 @@ import {TOP_MENUS, SIDE_MENUS} from "@/config/menu.data";
import {useLogoutMutation} from "@/query/auth";
import {useDialog} from "@/hooks/useDialog";
import LoginDialog from "@/components/dialog/loginDialog";
import { appendAdminRouteParam, hasAdminRouteParam } from "@/lib/admin-route";
type MainLayoutProps = {
children: ReactNode;
@@ -26,13 +27,15 @@ const MainLayout = ({ children }: MainLayoutProps) => {
const { showDialog } = useDialog();
const logoutMutation = useLogoutMutation();
const router = useRouter();
const searchParams = useSearchParams();
const isMounted = useMounted();
const [menuOpen, setMenuOpen] = useState(true);
const [selectedDiv, setSelectedDiv] = useState<DivKey>(getDivKey());
const isRouteAdmin = hasAdminRouteParam(searchParams);
const movePage = (path: string) => {
router.push(path);
router.push(appendAdminRouteParam(path, searchParams));
};
const openLoginDialog = () => {
@@ -60,7 +63,7 @@ const MainLayout = ({ children }: MainLayoutProps) => {
<Header
topMenus={TOP_MENUS}
userName={auth.user?.userName || ""}
isAuthenticated={auth.user != null}
isAuthenticated={isRouteAdmin}
onNavigate={movePage}
onLogin={openLoginDialog}
onLogout={handleLogout}

View File

@@ -2,11 +2,11 @@ export const SITE_TITLE = "화재보험협회 대시보드"
export const CATEGORY_KEY_MAP: Record<string, string> = {
'2601009_A': '안전점검',
//'2604005_E': 'UCIS',
//'2604005_D': 'Bridge플랫폼',
//'2604005_C': '방재컨설팅',
//'2604005_A': '보험 공동인수',
//'2604005_B': '화재조사',
'2604005_E': 'UCIS',
'2604005_D': 'Bridge플랫폼',
'2604005_C': '방재컨설팅',
'2604005_A': '보험 공동인수',
'2604005_B': '화재조사',
};
export const CATEGORY_PATH_MAP: Record<string, string> = {