From f915f8ab4b46ebc3e7562ae2768045c44808bbff Mon Sep 17 00:00:00 2001 From: bicochan Date: Mon, 30 Jun 2025 16:13:26 +0900 Subject: [PATCH] =?UTF-8?q?remove:=20getClientIp=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/cs/app/api/getClientIp/route.ts | 16 ------- apps/cs/src/entities/ip/index.ts | 1 - .../src/entities/ip/lib/client-ip-guard.tsx | 48 ------------------- 3 files changed, 65 deletions(-) delete mode 100644 apps/cs/app/api/getClientIp/route.ts delete mode 100644 apps/cs/src/entities/ip/lib/client-ip-guard.tsx diff --git a/apps/cs/app/api/getClientIp/route.ts b/apps/cs/app/api/getClientIp/route.ts deleted file mode 100644 index ec9ff72d5..000000000 --- a/apps/cs/app/api/getClientIp/route.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { NextRequest, NextResponse } from "next/server"; - -export async function GET(request: NextRequest) { - const ipAddress = - request.headers.get("x-forwarded-for")?.split(",")[0] || "unknown"; - - const ipv4Regex = /^::ffff:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/; - const match = ipAddress.match(ipv4Regex); - - const normalizedIp = match ? match[1] : ipAddress; - - return NextResponse.json({ - originalIp: ipAddress, - normalizedIp: normalizedIp, - }); -} diff --git a/apps/cs/src/entities/ip/index.ts b/apps/cs/src/entities/ip/index.ts index ef1c5be33..2d244138d 100644 --- a/apps/cs/src/entities/ip/index.ts +++ b/apps/cs/src/entities/ip/index.ts @@ -7,4 +7,3 @@ export { type IpList, type IP, } from "./model/ip-interface"; -export { ClientIpGuard } from "./lib/client-ip-guard"; diff --git a/apps/cs/src/entities/ip/lib/client-ip-guard.tsx b/apps/cs/src/entities/ip/lib/client-ip-guard.tsx deleted file mode 100644 index f3ae452ce..000000000 --- a/apps/cs/src/entities/ip/lib/client-ip-guard.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { useEffect, useState } from "react"; -import { useQueryClient } from "@tanstack/react-query"; -import { SiteApi } from "@/entities/site/@x/ip"; -import { ENDPOINT, SITE_ID } from "@/shared/config"; -import { IpApi } from "../api/ip-service"; - -type ClientIpResponse = { - originalIp: string; - normalizedIp: string; -}; - -const ClientIpGuard = ({ children }: { children: React.ReactNode }) => { - const queryClient = useQueryClient(); - const [isAllowed, setIsAllowed] = useState(true); - - useEffect(() => { - (async () => { - const response = await fetch("/api/getClientIp"); - const { normalizedIp } = (await response.json()) as ClientIpResponse; - - if (!normalizedIp || !SITE_ID) return; - - const siteInfo = await queryClient.ensureQueryData({ - queryKey: [ENDPOINT.CMS_SERVICE.SITES, SITE_ID], - queryFn: () => SiteApi.siteDetail(SITE_ID), - }); - - if (siteInfo.siteKndCd === "O") return; - - const { content: ipList } = await IpApi.getIpList({ - siteId: SITE_ID, - prmYn: "Y", - }); - - const allowedClientIp = ipList.some((ip) => ip.ipAddr === normalizedIp); - setIsAllowed(allowedClientIp); - })(); - }, []); - - if (!isAllowed) { - alert("허용되지 않은 IP로 접근하였습니다."); - return <>; - } - - return <>{children}; -}; - -export { ClientIpGuard };