wr: 로그인 화면 이동
This commit is contained in:
@@ -18,5 +18,8 @@ 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_CM_LOGIN_PAGE_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
|
||||
@@ -21,11 +21,36 @@ 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 userInfo = useUserStore((state) => state.userInfo);
|
||||
const setUserInfo = useUserStore((state) => state.setUserInfo);
|
||||
|
||||
/**
|
||||
* 로그인 화면으로 이동한다.
|
||||
* 다른 도메인(포털)이면 브라우저 이동, 같은 앱이면 Next 라우터로 이동한다.
|
||||
*/
|
||||
function goToLogin() {
|
||||
if (isExternalLoginUrl(AUTH_LOGIN_REDIRECT_URL)) {
|
||||
window.location.replace(AUTH_LOGIN_REDIRECT_URL);
|
||||
return;
|
||||
}
|
||||
router.replace(AUTH_LOGIN_REDIRECT_URL);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
// 페이지 새로고침 시 silentRefresh 타이머 복구
|
||||
const token = getToken(CLAIM_NAME);
|
||||
@@ -44,7 +69,7 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
|
||||
async function authCheck() {
|
||||
const userId = getToken(AUTH_USER_ID);
|
||||
if (!userId) {
|
||||
router.replace(AUTH_LOGIN_REDIRECT_URL);
|
||||
goToLogin();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,7 +88,7 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
|
||||
console.error(error);
|
||||
setUserInfo(null);
|
||||
if (!isAtLoginRedirectUrl(AUTH_LOGIN_REDIRECT_URL)) {
|
||||
router.replace(AUTH_LOGIN_REDIRECT_URL);
|
||||
goToLogin();
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
@@ -73,7 +98,7 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
|
||||
function handleAuthLogout() {
|
||||
setUserInfo(null);
|
||||
if (!isAtLoginRedirectUrl(AUTH_LOGIN_REDIRECT_URL)) {
|
||||
router.replace(AUTH_LOGIN_REDIRECT_URL);
|
||||
goToLogin();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,11 @@ 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 || "/auth/login";
|
||||
process.env.NEXT_PUBLIC_AUTH_LOGIN_REDIRECT_URL ||
|
||||
process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_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";
|
||||
|
||||
Reference in New Issue
Block a user