feat: 로그인 분기 처리

This commit is contained in:
swcho
2025-11-05 10:25:13 +09:00
parent 6a50f12d89
commit b011644d38
8 changed files with 63 additions and 58 deletions
+1
View File
@@ -15,6 +15,7 @@ NEXT_PUBLIC_DC_URL = https://apigateway.apps.rsonesoft.com/dc-service
NEXT_PUBLIC_SEWERAGE_API_URL = http://con.mind-one.co.kr:11083/sewerage-service # 개발 서버 API
NEXT_PUBLIC_NGII_URL = https://map.ngii.go.kr
NEXT_PUBLIC_NGII_PARAM = 04trYP9_xwLAfALjwZ-B8g&service=WMTS&request=GetTile&version=1.0.0&format=image/png&layer=korean_map&style=korean&tilematrixset=korean&tilematrix={z}&tilecol={x}&tilerow={y}
NEXT_PUBLIC_CM_LOGIN_PAGE_URL = http://dev.onasys.co.kr:3000/auth/login
#NEXT_PUBLIC_SERVER_API_URL = http://localhost:8883/operation-service
+13 -12
View File
@@ -9,20 +9,21 @@ import { useRouter } from "next/navigation";
export default function Home() {
const router = useRouter();
const checkToken = getCookie(AUTH_USER_ID);
const hostname = window.location.hostname;
useEffect(() => {
if (!checkToken) {
async function doLogin() {
try {
await LoginApi.login({ userId: "CLEANWATER", password: "gktneh12!@" });
window.location.href = "/pages/dashboard";
} catch (err) {
console.error("로그인 실패", err);
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr") {
if (!checkToken) {
async function doLogin() {
try {
await LoginApi.login({ userId: "CLEANWATER", password: "gktneh12!@" });
window.location.href = "/pages/dashboard";
} catch (err) {
console.error("로그인 실패", err);
}
}
}
doLogin();
} else {
router.push("/pages/dashboard");
}
doLogin();
} else router.push("/pages/dashboard");
} else router.push("/pages/dashboard");
}, []);
}
@@ -1,17 +1,18 @@
"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useRouter, usePathname } from "next/navigation";
import { client } from "@/src/shared/api";
import type { IUserInfo } from "@/src/shared/store";
import { useUserStore, getCookie } from "@/src/shared/lib";
import { ENDPOINT, AUTH_USER_ID } from "@/src/shared/config";
import { LoginApi } from "../api/login-service";
// const LOGIN_PAGE_URL = process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_URL || "http://localhost:3001/auth/login"; // 개발 환경 URL
const LOGIN_PAGE_URL = process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_URL || "http://localhost:3001/auth/login"; // 개발 환경 URL
const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
const router = useRouter();
const pathname = usePathname();
const { userInfo, setUserInfo } = useUserStore((state) => state);
async function authCheck() {
@@ -40,19 +41,19 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
console.error("Token refresh failed:", refreshError);
setUserInfo(null);
// const hostname = window.location.hostname;
const hostname = window.location.hostname;
// 개발 환경에서는 localhost 도메인 사용
// if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr")
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr")
router.push("/"); // 개발시 홈으로 돌아가기
// 운영 환경에서는 서브도메인을 포함한 최상위 도메인 사용
// router.push는 같은 Next.js 앱 내에서만 작동하므로 다른 앱으로 이동할 때는 window.location.href 사용
// if (hostname.includes("hasuon.or.kr")) window.location.href = LOGIN_PAGE_URL; // 세션 만료 시 CM 로그인 페이지로 리다이렉트
if (hostname.includes("hasuon.or.kr")) window.location.href = LOGIN_PAGE_URL; // 세션 만료 시 CM 로그인 페이지로 리다이렉트
}
}
})();
}, []);
}, [pathname]);
return <>{children}</>;
};
+13 -14
View File
@@ -23,23 +23,22 @@ import { useRouter } from "next/navigation";
export default function Home() {
const router = useRouter();
const userId = "CLEANWATER";
const password = "gktneh12!@";
const checkToken = getCookie(AUTH_USER_ID);
const hostname = window.location.hostname;
useEffect(() => {
if (!checkToken) {
async function doLogin() {
try {
await LoginApi.login({ userId, password });
window.location.href = "/map";
} catch (err) {
console.error("로그인 실패", err);
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr") {
if (!checkToken) {
async function doLogin() {
try {
await LoginApi.login({ userId: "CLEANWATER", password: "gktneh12!@" });
window.location.href = "/map";
} catch (err) {
console.error("로그인 실패", err);
}
}
}
doLogin();
} else {
router.push("/map");
}
doLogin();
} else router.push("/map");
} else router.push("/map");
}, []);
}
@@ -1,7 +1,7 @@
"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useRouter, usePathname } from "next/navigation";
import { client } from "@/shared/api";
import type { IUserInfo } from "@/shared/store";
import { useUserStore } from "@/shared/lib";
@@ -10,10 +10,11 @@ import { getCookie } from "@/shared/lib";
import { LoginApi } from "../api/login-service";
// const LOGIN_PAGE_URL = process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_URL || "http://dev.onasys.co.kr:3000/auth/login"; // 로그인 페이지 URL
const LOGIN_PAGE_URL = process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_URL || "http://dev.onasys.co.kr:3000/auth/login"; // 로그인 페이지 URL
const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
const router = useRouter();
const pathname = usePathname();
const { userInfo, setUserInfo } = useUserStore((state) => state);
async function authCheck() {
@@ -42,19 +43,19 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
console.error("Token refresh failed:", refreshError);
setUserInfo(null);
// const hostname = window.location.hostname;
const hostname = window.location.hostname;
// 개발 환경에서는 localhost 도메인 사용
// if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr")
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr")
router.push("/"); // 개발시 홈으로 돌아가기
// 운영 환경에서는 서브도메인을 포함한 최상위 도메인 사용
// router.push는 같은 Next.js 앱 내에서만 작동하므로 다른 앱으로 이동할 때는 window.location.href 사용
// if (hostname.includes("hasuon.or.kr")) window.location.href = LOGIN_PAGE_URL; // 세션 만료 시 CM 로그인 페이지로 리다이렉트
if (hostname.includes("hasuon.or.kr")) window.location.href = LOGIN_PAGE_URL; // 세션 만료 시 CM 로그인 페이지로 리다이렉트
}
}
})();
}, []);
}, [pathname]);
return <>{children}</>;
};
+2
View File
@@ -14,8 +14,10 @@ NEXT_PUBLIC_LX_GEOSERVER_URL = http://con.mind-one.co.kr:11306/geoserver
NEXT_PUBLIC_WR_SERVER_API_URL = http://con.mind-one.co.kr:11083/reuse-service/api/v1
#NEXT_PUBLIC_WR_SERVER_API_URL = http://192.168.1.222:8883/reuse-service/api/v1
NEXT_PUBLIC_SEWERAGE_API_URL = http://con.mind-one.co.kr:11083/sewerage-service # 개발 서버 API
# NEXT_PUBLIC_SEWERAGE_API_URL=http://192.168.1.66:8883/sewerage-service
NEXT_PUBLIC_NGII_URL = https://map.ngii.go.kr
NEXT_PUBLIC_NGII_PARAM = 04trYP9_xwLAfALjwZ-B8g&service=WMTS&request=GetTile&version=1.0.0&format=image/png&layer=korean_map&style=korean&tilematrixset=korean&tilematrix={z}&tilecol={x}&tilerow={y}
NEXT_PUBLIC_CM_LOGIN_PAGE_URL = http://dev.onasys.co.kr:3000/auth/login
NEXT_PUBLIC_FINDADRESS_URL = https://business.juso.go.kr/addrlink/addrLinkApi.do
NEXT_PRIVATE_WR_ADDRESS_KEY = devU01TX0FVVEgyMDI1MDgyNTEwMzkwNDExNjEwNTM=
+13 -14
View File
@@ -9,23 +9,22 @@ import { useRouter } from "next/navigation";
export default function Home() {
const router = useRouter();
const userId = "CLEANWATER";
const password = "gktneh12!@";
const checkToken = getCookie(AUTH_USER_ID);
const hostname = window.location.hostname;
useEffect(() => {
if (!checkToken) {
async function doLogin() {
try {
await LoginApi.login({ userId, password });
window.location.href = "/map/mainMap";
} catch (err) {
console.error("로그인 실패", err);
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr") {
if (!checkToken) {
async function doLogin() {
try {
await LoginApi.login({ userId: "CLEANWATER", password: "gktneh12!@" });
window.location.href = "/map/mainMap";
} catch (err) {
console.error("로그인 실패", err);
}
}
}
doLogin();
} else {
router.push("/map/mainMap");
}
doLogin();
} else router.push("/map/mainMap");
} else router.push("/map/mainMap");
}, []);
}
@@ -1,7 +1,7 @@
"use client";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useRouter, usePathname } from "next/navigation";
import { client } from "../../../shared/api";
import type { IUserInfo } from "../../../shared/store";
import { useUserStore } from "../../../shared/lib";
@@ -10,10 +10,11 @@ import { getCookie } from "../../../shared/lib";
import { LoginApi } from "../api/login-service";
// const LOGIN_PAGE_URL = process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_URL || "http://localhost:3000/auth/login"; // 로그인 페이지 URL
const LOGIN_PAGE_URL = process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_URL || "http://localhost:3000/auth/login"; // 로그인 페이지 URL
const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
const router = useRouter();
const pathname = usePathname();
const { userInfo, setUserInfo } = useUserStore((state) => state);
async function authCheck() {
@@ -42,19 +43,19 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
console.error("Token refresh failed:", refreshError);
setUserInfo(null);
// const hostname = window.location.hostname;
const hostname = window.location.hostname;
// 개발 환경에서는 localhost 도메인 사용
// if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr")
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr")
router.push("/"); // 개발시 홈으로 돌아가기
// 운영 환경에서는 서브도메인을 포함한 최상위 도메인 사용
// router.push는 같은 Next.js 앱 내에서만 작동하므로 다른 앱으로 이동할 때는 window.location.href 사용
// if (hostname.includes("hasuon.or.kr")) window.location.href = LOGIN_PAGE_URL; // 세션 만료 시 CM 로그인 페이지로 리다이렉트
if (hostname.includes("hasuon.or.kr")) window.location.href = LOGIN_PAGE_URL; // 세션 만료 시 CM 로그인 페이지로 리다이렉트
}
}
})();
}, []);
}, [pathname]);
return <>{children}</>;
};