remove: getClientIp 로직 제거
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
@@ -7,4 +7,3 @@ export {
|
||||
type IpList,
|
||||
type IP,
|
||||
} from "./model/ip-interface";
|
||||
export { ClientIpGuard } from "./lib/client-ip-guard";
|
||||
|
||||
@@ -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 };
|
||||
Reference in New Issue
Block a user