260508_17_ENH: 클라이언트 강력 요청으로 로그인 아예 걷고 파라미터 기반으로 admin 기능 우회
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
import { useSearchParams } from "next/navigation";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import DataTable from "@/components/table/DataTable";
|
import DataTable from "@/components/table/DataTable";
|
||||||
import type { DataColumn } from "@/components/table/types";
|
import type { DataColumn } from "@/components/table/types";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { DIV_KEY_MAP } from "@/config/kfpaConfig";
|
import { DIV_KEY_MAP } from "@/config/kfpaConfig";
|
||||||
import { useAuth } from "@/hooks/useAuth";
|
|
||||||
import { formatKoreanBaseDate } from "@/lib/utils";
|
import { formatKoreanBaseDate } from "@/lib/utils";
|
||||||
import { useWriteDivCommentMutation } from "@/query/admin";
|
import { useWriteDivCommentMutation } from "@/query/admin";
|
||||||
import { statisticsQueryKeys } from "@/query/key/keys";
|
import { statisticsQueryKeys } from "@/query/key/keys";
|
||||||
@@ -15,6 +15,7 @@ import { useDivDetailDataQuery } from "@/query/statistics";
|
|||||||
import type { CommentValue, DivDetailData } from "@/types/kfpa";
|
import type { CommentValue, DivDetailData } from "@/types/kfpa";
|
||||||
import { Pencil, Save, X } from 'lucide-react';
|
import { Pencil, Save, X } from 'lucide-react';
|
||||||
import SectionTitle from "@/components/common/SectionTitle";
|
import SectionTitle from "@/components/common/SectionTitle";
|
||||||
|
import { hasAdminRouteParam } from "@/lib/admin-route";
|
||||||
|
|
||||||
export type SafetyInspectionDivDetailProps = {
|
export type SafetyInspectionDivDetailProps = {
|
||||||
selectedDiv: string;
|
selectedDiv: string;
|
||||||
@@ -85,7 +86,7 @@ const createDraft = (columns: Array<{ key: string }>, source?: Record<string, Co
|
|||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
const SafetyInspectionDivDetail = ({ selectedDiv }: SafetyInspectionDivDetailProps) => {
|
const SafetyInspectionDivDetail = ({ selectedDiv }: SafetyInspectionDivDetailProps) => {
|
||||||
const { auth } = useAuth();
|
const searchParams = useSearchParams();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { data, isLoading, isError } = useDivDetailDataQuery(selectedDiv, selectedDiv !== "-1");
|
const { data, isLoading, isError } = useDivDetailDataQuery(selectedDiv, selectedDiv !== "-1");
|
||||||
const writeMutation = useWriteDivCommentMutation();
|
const writeMutation = useWriteDivCommentMutation();
|
||||||
@@ -103,7 +104,7 @@ const SafetyInspectionDivDetail = ({ selectedDiv }: SafetyInspectionDivDetailPro
|
|||||||
}, [commentColumns, detail?.commentValues, selectedDiv]);
|
}, [commentColumns, detail?.commentValues, selectedDiv]);
|
||||||
|
|
||||||
const baseDateLabel = useMemo(() => formatKoreanBaseDate(), []);
|
const baseDateLabel = useMemo(() => formatKoreanBaseDate(), []);
|
||||||
const isAuthenticated = auth.user != null;
|
const isAuthenticated = hasAdminRouteParam(searchParams);
|
||||||
|
|
||||||
const rankRows: RankRow[] = useMemo(() => {
|
const rankRows: RankRow[] = useMemo(() => {
|
||||||
const ranks = detail?.csiRanks ?? {};
|
const ranks = detail?.csiRanks ?? {};
|
||||||
|
|||||||
@@ -69,27 +69,31 @@ const Header = ({
|
|||||||
<h1 className="font-bold content-text-2xl text-header-color">{SITE_TITLE}</h1>
|
<h1 className="font-bold content-text-2xl text-header-color">{SITE_TITLE}</h1>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex min-w-0 items-center justify-end gap-4">
|
<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}
|
{isAuthenticated && (
|
||||||
</span>
|
<span className="content-text-base text-header-color hidden max-w-40 truncate sm:inline font-bold">
|
||||||
)}
|
{userName}
|
||||||
<Button
|
</span>
|
||||||
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>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import {ReactNode, useEffect, useState} from "react";
|
import {ReactNode, useEffect, useState} from "react";
|
||||||
import {useRouter} from "next/navigation";
|
import {useRouter, useSearchParams} from "next/navigation";
|
||||||
import {DivKey} from "@/types/kfpa";
|
import {DivKey} from "@/types/kfpa";
|
||||||
import {useAuth} from "@/hooks/useAuth";
|
import {useAuth} from "@/hooks/useAuth";
|
||||||
import {LayoutCategoryProvider} from "./LayoutCategoryContext";
|
import {LayoutCategoryProvider} from "./LayoutCategoryContext";
|
||||||
@@ -12,6 +12,7 @@ import {TOP_MENUS, SIDE_MENUS} from "@/config/menu.data";
|
|||||||
import {useLogoutMutation} from "@/query/auth";
|
import {useLogoutMutation} from "@/query/auth";
|
||||||
import {useDialog} from "@/hooks/useDialog";
|
import {useDialog} from "@/hooks/useDialog";
|
||||||
import LoginDialog from "@/components/dialog/loginDialog";
|
import LoginDialog from "@/components/dialog/loginDialog";
|
||||||
|
import { appendAdminRouteParam, hasAdminRouteParam } from "@/lib/admin-route";
|
||||||
|
|
||||||
type MainLayoutProps = {
|
type MainLayoutProps = {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
@@ -26,13 +27,15 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
|||||||
const { showDialog } = useDialog();
|
const { showDialog } = useDialog();
|
||||||
const logoutMutation = useLogoutMutation();
|
const logoutMutation = useLogoutMutation();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
const isMounted = useMounted();
|
const isMounted = useMounted();
|
||||||
|
|
||||||
const [menuOpen, setMenuOpen] = useState(true);
|
const [menuOpen, setMenuOpen] = useState(true);
|
||||||
const [selectedDiv, setSelectedDiv] = useState<DivKey>(getDivKey());
|
const [selectedDiv, setSelectedDiv] = useState<DivKey>(getDivKey());
|
||||||
|
const isRouteAdmin = hasAdminRouteParam(searchParams);
|
||||||
|
|
||||||
const movePage = (path: string) => {
|
const movePage = (path: string) => {
|
||||||
router.push(path);
|
router.push(appendAdminRouteParam(path, searchParams));
|
||||||
};
|
};
|
||||||
|
|
||||||
const openLoginDialog = () => {
|
const openLoginDialog = () => {
|
||||||
@@ -60,7 +63,7 @@ const MainLayout = ({ children }: MainLayoutProps) => {
|
|||||||
<Header
|
<Header
|
||||||
topMenus={TOP_MENUS}
|
topMenus={TOP_MENUS}
|
||||||
userName={auth.user?.userName || ""}
|
userName={auth.user?.userName || ""}
|
||||||
isAuthenticated={auth.user != null}
|
isAuthenticated={isRouteAdmin}
|
||||||
onNavigate={movePage}
|
onNavigate={movePage}
|
||||||
onLogin={openLoginDialog}
|
onLogin={openLoginDialog}
|
||||||
onLogout={handleLogout}
|
onLogout={handleLogout}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ export const SITE_TITLE = "화재보험협회 대시보드"
|
|||||||
|
|
||||||
export const CATEGORY_KEY_MAP: Record<string, string> = {
|
export const CATEGORY_KEY_MAP: Record<string, string> = {
|
||||||
'2601009_A': '안전점검',
|
'2601009_A': '안전점검',
|
||||||
//'2604005_E': 'UCIS',
|
'2604005_E': 'UCIS',
|
||||||
//'2604005_D': 'Bridge플랫폼',
|
'2604005_D': 'Bridge플랫폼',
|
||||||
//'2604005_C': '방재컨설팅',
|
'2604005_C': '방재컨설팅',
|
||||||
//'2604005_A': '보험 공동인수',
|
'2604005_A': '보험 공동인수',
|
||||||
//'2604005_B': '화재조사',
|
'2604005_B': '화재조사',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CATEGORY_PATH_MAP: Record<string, string> = {
|
export const CATEGORY_PATH_MAP: Record<string, string> = {
|
||||||
|
|||||||
Reference in New Issue
Block a user