NEXT_PUBLIC_CM_LOGIN_PAGE_URL 삭제 및 common-codes 수정
This commit is contained in:
+5
-3
@@ -6,7 +6,7 @@ NEXT_PUBLIC_ACCESS_TOKEN = access-token
|
||||
NEXT_PUBLIC_REFRESH_TOKEN = refresh-token
|
||||
NEXT_PUBLIC_PROXY_HOST = http://localhost:3000
|
||||
NEXT_PUBLIC_SUB_DOMAIN = http://localhost:13000
|
||||
#NEXT_PUBLIC_CM_LOGIN_PAGE_URL = http://localhost:3001/auth/login
|
||||
#NEXT_PUBLIC_AUTH_LOGIN_REDIRECT_URL = http://localhost:3001/auth/login
|
||||
SERVER_API_URL = http://con.mind-one.co.kr:11083/operation-service/api/v1
|
||||
# FO_SERVER_API_URL = http://con.mind-one.co.kr:11083/operation-service/api/v1
|
||||
FO_SERVER_API_URL = http://localhost:3000/operation-service/api/v1
|
||||
@@ -19,8 +19,10 @@ DC_URL = https://apigateway.apps.rsonesoft.com/dc-service
|
||||
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_CM_LOGIN_PAGE_URL = /
|
||||
# NEXT_PUBLIC_AUTH_LOGIN_REDIRECT_URL = http://dev.onasys.co.kr:3000/auth/login
|
||||
# 로그인 이동 주소: 설정하지 않으면 /auth/login
|
||||
# (.env.local은 운영 빌드에서도 .env.production보다 우선하므로 값을 켜지 않는다)
|
||||
# NEXT_PUBLIC_AUTH_LOGIN_REDIRECT_URL = /auth/login
|
||||
NEXT_PUBLIC_COOKIE_COMAIN=.mind-one.co.kr
|
||||
|
||||
REACT_EDITOR=atom
|
||||
@@ -6,7 +6,7 @@ NEXT_PUBLIC_ACCESS_TOKEN = access-token
|
||||
NEXT_PUBLIC_REFRESH_TOKEN = refresh-token
|
||||
NEXT_PUBLIC_PROXY_HOST = http://con.mind-one.co.kr:11300
|
||||
NEXT_PUBLIC_SUB_DOMAIN = http://con.mind-one.co.kr:13000
|
||||
NEXT_PUBLIC_CM_LOGIN_PAGE_URL = http://dev.onasys.co.kr:3000/auth/login
|
||||
NEXT_PUBLIC_AUTH_LOGIN_REDIRECT_URL = /auth/login
|
||||
SERVER_API_URL = http://con.mind-one.co.kr:11083/operation-service/api/v1
|
||||
FO_SERVER_API_URL = http://con.mind-one.co.kr:11083/operation-service/api/v1
|
||||
WR_SERVER_API_URL = http://con.mind-one.co.kr:11083/reuse-service/api/v1
|
||||
@@ -17,5 +17,4 @@ DC_URL = https://apigateway.apps.rsonesoft.com/dc-service
|
||||
SEWERAGE_API_URL = http://con.mind-one.co.kr:11083/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 = /
|
||||
NEXT_PUBLIC_COOKIE_COMAIN=.mind-one.co.kr
|
||||
@@ -6,7 +6,7 @@ NEXT_PUBLIC_AUTH_USER_ID = token-id
|
||||
NEXT_PUBLIC_ACCESS_TOKEN = access-token
|
||||
NEXT_PUBLIC_REFRESH_TOKEN = refresh-token
|
||||
#NEXT_PUBLIC_PROXY_HOST = https://devlarva.hasuon.or.kr
|
||||
#NEXT_PUBLIC_CM_LOGIN_PAGE_URL = https://devqueen.hasuon.or.kr/auth/login
|
||||
#NEXT_PUBLIC_AUTH_LOGIN_REDIRECT_URL = https://devqueen.hasuon.or.kr/auth/login
|
||||
SERVER_API_URL = http://apigateway.iipbs-was.svc.cluster.local:8000/operation-service/api/v1
|
||||
FO_SERVER_API_URL = http://apigateway.iipbs-was.svc.cluster.local:8000/operation-service/api/v1
|
||||
WR_SERVER_API_URL = http://apigateway.iipbs-was.svc.cluster.local:8000/reuse-service/api/v1
|
||||
@@ -18,8 +18,7 @@ DC_URL = http://apigateway.iipbs-was.svc.cluster.local:8000/dc-service
|
||||
SEWERAGE_API_URL = http://apigateway.iipbs-was.svc.cluster.local:8000/sewerage-service
|
||||
NEXT_PUBLIC_NGII_URL = http://172.29.143.87/poiact
|
||||
NEXT_PUBLIC_NGII_PARAM = BDE2BEF39DAFEC293AB6730150F222AC&service=WMTS&request=GetTile&version=1.0.0&format=image/png&layer=korean_map&style=korean&tilematrixset=korean&tilematrix={z}&tilecol={y}&tilerow={x}
|
||||
#NEXT_PUBLIC_CM_LOGIN_PAGE_URL = http://dev.onasys.co.kr:3000/auth/login
|
||||
#NEXT_PUBLIC_AUTH_LOGIN_REDIRECT_URL = http://dev.onasys.co.kr:3000/auth/login
|
||||
# 로그인 필요(토큰 없음·401·갱신 실패) 시 공통 포털 로그인으로 이동
|
||||
NEXT_PUBLIC_CM_LOGIN_PAGE_URL = https://portal.hasuon.or.kr/auth/login
|
||||
NEXT_PUBLIC_AUTH_LOGIN_REDIRECT_URL = https://portal.hasuon.or.kr/auth/login
|
||||
NEXT_PUBLIC_COOKIE_DOMAIN=.hasuon.or.kr
|
||||
@@ -9,9 +9,6 @@ export default function AuthLayout({
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<html lang="ko">
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
// <html>, <body>는 루트 레이아웃(app/layout.tsx)에서 그린다
|
||||
return children;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import { CLAIM_NAME, SITE_ID } from "@/src/shared/config/env";
|
||||
import { AUTH_LOGIN_REDIRECT_URL, CLAIM_NAME, SITE_ID } from "@/src/shared/config/env";
|
||||
import { tokenManager } from "@/src/entities/auth/lib/token-manager";
|
||||
import { getRemainingMs } from "@common/auth";
|
||||
import { DEV_URL_FO, DEV_URL_WR, LOCAL_URL } from "./config/env";
|
||||
|
||||
const LOGIN_PAGE_URL =
|
||||
process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_URL || "/auth/login";
|
||||
|
||||
// client 화면인 경우, 토큰 만료여부 점검하여 로그인 페이지로 이동
|
||||
const handleUnauthorizedResponse = () => {
|
||||
if (typeof window === "undefined") return;
|
||||
@@ -23,7 +20,7 @@ const handleUnauthorizedResponse = () => {
|
||||
window.location.pathname.startsWith("/auth/login/");
|
||||
|
||||
if (!isLoginPage) {
|
||||
window.location.assign(LOGIN_PAGE_URL);
|
||||
window.location.assign(AUTH_LOGIN_REDIRECT_URL);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+2
-12
@@ -1,5 +1,4 @@
|
||||
"use client";
|
||||
import { authService } from "@/src/entities/auth";
|
||||
import { useEffect } from "react";
|
||||
import { AUTH_USER_ID } from "@/src/shared/config";
|
||||
import { getCookie } from "@/src/shared/lib/cookie";
|
||||
@@ -14,17 +13,8 @@ export default function Home() {
|
||||
const hostname = window.location.hostname;
|
||||
|
||||
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "con.mind-one.co.kr") {
|
||||
if (!checkToken) {
|
||||
async function doLogin() {
|
||||
try {
|
||||
await authService.login({ userId: "CLEANWATER", password: "gktneh12!@" });
|
||||
window.location.href = "/pages/dashboard";
|
||||
} catch (err) {
|
||||
console.error("로그인 실패", err);
|
||||
}
|
||||
}
|
||||
doLogin();
|
||||
} else router.push("/pages/dashboard");
|
||||
if (!checkToken) router.push("/auth/login");
|
||||
else router.push("/pages/dashboard");
|
||||
} else router.push("/pages/dashboard");
|
||||
}, []);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
|
||||
import { isAxiosError } from "axios";
|
||||
|
||||
@@ -21,35 +21,20 @@ import { authService } from "../api/auth-service";
|
||||
|
||||
import { getToken, setupRefreshTimer } from "./token-manager";
|
||||
|
||||
/**
|
||||
* 로그인 주소가 다른 도메인(예: 공통 포털)인지 확인한다.
|
||||
* @param url 로그인 이동 주소(상대경로 또는 절대경로)
|
||||
* @returns 현재 사이트와 origin이 다르면 true
|
||||
*/
|
||||
function isExternalLoginUrl(url: string): boolean {
|
||||
try {
|
||||
return new URL(url, window.location.href).origin !== window.location.origin;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const userInfo = useUserStore((state) => state.userInfo);
|
||||
const setUserInfo = useUserStore((state) => state.setUserInfo);
|
||||
// 화면(children) 표시 여부. false인 동안에는 자식 화면의 API 호출이 시작되지 않는다
|
||||
const [canRender, setCanRender] = useState(false);
|
||||
|
||||
/**
|
||||
* 로그인 화면으로 이동한다.
|
||||
* 다른 도메인(포털)이면 브라우저 이동, 같은 앱이면 Next 라우터로 이동한다.
|
||||
*/
|
||||
function goToLogin() {
|
||||
if (isExternalLoginUrl(AUTH_LOGIN_REDIRECT_URL)) {
|
||||
window.location.replace(AUTH_LOGIN_REDIRECT_URL);
|
||||
return;
|
||||
// 로그인 화면이거나 토큰이 있을 때만 화면을 연다. 로그인 화면으로 이동하면 다시 확인한다
|
||||
useEffect(() => {
|
||||
if (isAtLoginRedirectUrl(AUTH_LOGIN_REDIRECT_URL) || getToken(AUTH_USER_ID)) {
|
||||
setCanRender(true);
|
||||
}
|
||||
router.replace(AUTH_LOGIN_REDIRECT_URL);
|
||||
}
|
||||
}, [pathname]);
|
||||
|
||||
useEffect(() => {
|
||||
// 페이지 새로고침 시 silentRefresh 타이머 복구
|
||||
@@ -69,7 +54,7 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
|
||||
async function authCheck() {
|
||||
const userId = getToken(AUTH_USER_ID);
|
||||
if (!userId) {
|
||||
goToLogin();
|
||||
router.replace(AUTH_LOGIN_REDIRECT_URL);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,7 +73,7 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
|
||||
console.error(error);
|
||||
setUserInfo(null);
|
||||
if (!isAtLoginRedirectUrl(AUTH_LOGIN_REDIRECT_URL)) {
|
||||
goToLogin();
|
||||
router.replace(AUTH_LOGIN_REDIRECT_URL);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
@@ -98,7 +83,7 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
|
||||
function handleAuthLogout() {
|
||||
setUserInfo(null);
|
||||
if (!isAtLoginRedirectUrl(AUTH_LOGIN_REDIRECT_URL)) {
|
||||
goToLogin();
|
||||
router.replace(AUTH_LOGIN_REDIRECT_URL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +92,7 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
|
||||
window.removeEventListener("auth:logout", handleAuthLogout);
|
||||
}, []);
|
||||
|
||||
return <>{children}</>;
|
||||
return <>{canRender ? children : null}</>;
|
||||
};
|
||||
|
||||
export { AuthWrapper };
|
||||
|
||||
@@ -16,18 +16,12 @@ export const SERVER_API_URL =
|
||||
export const SERVER_API_CS_TUS_URL =
|
||||
process.env.NEXT_PUBLIC_CS_TUS_UPLOAD ||
|
||||
"/attach-service/api/v1/tus/upload";
|
||||
// 로그인 이동 주소: @common/network getAuthLoginRedirectUrl()과 같은 순서로 찾는다
|
||||
// 로그인 이동 주소: 상대경로 또는 다른 도메인(공통 포털)의 절대경로
|
||||
export const AUTH_LOGIN_REDIRECT_URL =
|
||||
process.env.NEXT_PUBLIC_AUTH_LOGIN_REDIRECT_URL ||
|
||||
process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_URL ||
|
||||
"/auth/login";
|
||||
process.env.NEXT_PUBLIC_AUTH_LOGIN_REDIRECT_URL || "/auth/login";
|
||||
export const CLAIM_NAME = process.env.NEXT_PUBLIC_CLAIM_NAME || "Authorization";
|
||||
export const ACCESS_TOKEN = process.env.NEXT_PUBLIC_ACCESS_TOKEN || "access-token";
|
||||
export const REFRESH_TOKEN =process.env.NEXT_PUBLIC_REFRESH_TOKEN || "refresh-token";
|
||||
export const ACCESS_TOKEN = process.env.NEXT_PUBLIC_ACCESS_TOKEN || "access-token";
|
||||
export const REFRESH_TOKEN = process.env.NEXT_PUBLIC_REFRESH_TOKEN || "refresh-token";
|
||||
export const AUTH_USER_ID = process.env.NEXT_PUBLIC_AUTH_USER_ID || "token-id";
|
||||
export const SERVER_SEWERAGE_API_URL = process.env.SEWERAGE_API_URL;
|
||||
export const COOKIE_DOMAIN = process.env.NEXT_PUBLIC_COOKIE_DOMAIN;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user