From 1ec26b3de2970617ef332c5b0a63960f59b137bf Mon Sep 17 00:00:00 2001 From: yschoi Date: Thu, 10 Jul 2025 13:13:07 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=EC=BF=A0=ED=82=A4=20=EC=9C=A0=ED=8B=B8=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EA=B2=BD=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sn/app/components/lib/utils/fileDeleteUtil.tsx | 2 +- apps/sn/app/components/lib/utils/fileUploadUtil.tsx | 2 +- apps/sn/app/components/lib/utils/index.tsx | 1 - apps/sn/src/entities/auth/lib/auth-wrapper.tsx | 2 +- apps/sn/src/entities/auth/lib/token-manager.ts | 2 +- apps/sn/src/entities/menu/lib/menu-wrapper.tsx | 2 +- apps/sn/src/shared/api/client.ts | 3 +++ .../lib/utils/cookie.tsx => src/shared/lib/cookie.ts} | 0 apps/sn/src/shared/lib/index.ts | 1 + 9 files changed, 9 insertions(+), 6 deletions(-) rename apps/sn/{app/components/lib/utils/cookie.tsx => src/shared/lib/cookie.ts} (100%) diff --git a/apps/sn/app/components/lib/utils/fileDeleteUtil.tsx b/apps/sn/app/components/lib/utils/fileDeleteUtil.tsx index f487034d1..4cadd12e8 100644 --- a/apps/sn/app/components/lib/utils/fileDeleteUtil.tsx +++ b/apps/sn/app/components/lib/utils/fileDeleteUtil.tsx @@ -1,4 +1,4 @@ -import { getCookie } from "@/components/lib/utils"; +import { getCookie } from "@/shared/lib"; import { ENDPOINT } from "../api/attachment/attachment-service"; const AUTH_USER_ID = process.env.NEXT_PUBLIC_AUTH_USER_ID || "token-id"; diff --git a/apps/sn/app/components/lib/utils/fileUploadUtil.tsx b/apps/sn/app/components/lib/utils/fileUploadUtil.tsx index 195a96b0d..3bfb35f00 100644 --- a/apps/sn/app/components/lib/utils/fileUploadUtil.tsx +++ b/apps/sn/app/components/lib/utils/fileUploadUtil.tsx @@ -1,5 +1,5 @@ import { Upload, type HttpResponse } from "tus-js-client"; -import { getCookie, setCookie } from "@/components/lib/utils"; +import { getCookie, setCookie } from "@/shared/lib"; import { ENDPOINT } from "../api/attachment/attachment-service"; const AUTH_USER_ID = process.env.NEXT_PUBLIC_AUTH_USER_ID || "token-id"; diff --git a/apps/sn/app/components/lib/utils/index.tsx b/apps/sn/app/components/lib/utils/index.tsx index 9a41c2740..272ca7ada 100644 --- a/apps/sn/app/components/lib/utils/index.tsx +++ b/apps/sn/app/components/lib/utils/index.tsx @@ -1,4 +1,3 @@ -export * from "./cookie"; export * from "./fileUploadUtil"; export * from "./fileDownload"; export * from './date' diff --git a/apps/sn/src/entities/auth/lib/auth-wrapper.tsx b/apps/sn/src/entities/auth/lib/auth-wrapper.tsx index c09ca55c6..4c4ce3645 100644 --- a/apps/sn/src/entities/auth/lib/auth-wrapper.tsx +++ b/apps/sn/src/entities/auth/lib/auth-wrapper.tsx @@ -6,7 +6,7 @@ import { client } from "@/shared/api"; import type { IUserInfo } from "@/shared/store"; import { useUserStore } from "@/shared/lib"; import { ENDPOINT, AUTH_USER_ID } from "@/shared/config"; -import { getCookie } from "@/components/lib/utils"; +import { getCookie } from "@/shared/lib"; import axios from "axios"; import { LoginApi } from "../api/login-service"; import { tokenManager } from "../lib/token-manager"; diff --git a/apps/sn/src/entities/auth/lib/token-manager.ts b/apps/sn/src/entities/auth/lib/token-manager.ts index bf3d68265..6387f06e5 100644 --- a/apps/sn/src/entities/auth/lib/token-manager.ts +++ b/apps/sn/src/entities/auth/lib/token-manager.ts @@ -1,5 +1,5 @@ import { AUTH_USER_ID, CLAIM_NAME } from "@/shared/config"; -import { getCookie, setCookie, removeCookie } from "@/components/lib/utils"; +import { getCookie, setCookie, removeCookie } from "@/shared/lib";; export class TokenManager { private static instance: TokenManager; diff --git a/apps/sn/src/entities/menu/lib/menu-wrapper.tsx b/apps/sn/src/entities/menu/lib/menu-wrapper.tsx index e00d3696e..79a29a09c 100644 --- a/apps/sn/src/entities/menu/lib/menu-wrapper.tsx +++ b/apps/sn/src/entities/menu/lib/menu-wrapper.tsx @@ -4,7 +4,7 @@ import { useEffect } from "react"; import { usePathname, useRouter } from "next/navigation"; import { MenuAuthorityApi } from "@/entities/menu-authority/@x/menu"; import { useAlertStore, useMenuStore } from "@/shared/lib"; -import { getCookie } from "@/components/lib/utils"; +import { getCookie } from "@/shared/lib";; import { SITE_ID } from "@/shared/config"; import { MenuApi } from "../api/menu-service"; import { getCurrentMenu } from "./utils"; diff --git a/apps/sn/src/shared/api/client.ts b/apps/sn/src/shared/api/client.ts index 709bb44a5..cf37e6671 100644 --- a/apps/sn/src/shared/api/client.ts +++ b/apps/sn/src/shared/api/client.ts @@ -1,6 +1,9 @@ import { Client } from "@common/network"; import { BASE_URL } from "../config/api"; import { SITE_ID } from "../config/env"; +import { setCookie } from "../lib"; + +setCookie("site-id-key", SITE_ID); export const client = Client.getInstance({ baseURL: BASE_URL, diff --git a/apps/sn/app/components/lib/utils/cookie.tsx b/apps/sn/src/shared/lib/cookie.ts similarity index 100% rename from apps/sn/app/components/lib/utils/cookie.tsx rename to apps/sn/src/shared/lib/cookie.ts diff --git a/apps/sn/src/shared/lib/index.ts b/apps/sn/src/shared/lib/index.ts index bca6d2476..b8b4c52c0 100644 --- a/apps/sn/src/shared/lib/index.ts +++ b/apps/sn/src/shared/lib/index.ts @@ -3,3 +3,4 @@ export { useAlertStore } from "./use-alert-store"; export { useMenuStore } from "./use-menu-store"; export { useUserStore } from "./use-user-store"; export { usePrompt } from "./use-prompt"; +export { getCookie, setCookie, removeCookie } from "./cookie"; From 2bf1f4ac7089fcf7ca87a0661908584908d3395f Mon Sep 17 00:00:00 2001 From: yschoi Date: Thu, 10 Jul 2025 14:26:35 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EB=A9=94=EC=9D=B8=EC=97=90=EC=84=9C=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sn/app/page.tsx | 71 +++++++------------ apps/sn/package.json | 3 +- .../sn/src/entities/auth/lib/auth-wrapper.tsx | 35 ++------- 3 files changed, 31 insertions(+), 78 deletions(-) diff --git a/apps/sn/app/page.tsx b/apps/sn/app/page.tsx index d19bd5e79..9bfdbb656 100644 --- a/apps/sn/app/page.tsx +++ b/apps/sn/app/page.tsx @@ -1,50 +1,29 @@ -import { Button } from "@common/components"; -import Link from "next/link"; -import { redirect } from "next/navigation"; +"use client"; +import { LoginApi } from "@/entities/auth"; +import { useEffect } from "react"; +import { getCookie } from "@/shared/lib"; +import { AUTH_USER_ID } from "@/shared/config"; +import { useRouter } from "next/navigation"; export default function Home() { - redirect("/map"); + const router = useRouter(); + const userId = "admin1gmail"; + const password = "test1234!"; + const checkToken = getCookie(AUTH_USER_ID); - // return ( - //
- //
- //

하수관망도

- //
- // - // - // - //
- //
- //
- //

운영정보 관리

- //
- // - // - // - // - // - // - //
- //
- //
- //

- // I/I 분석(기초정보 설정) - //

- //
- // - // - // - // - // - // - // - // - // - // - // - // - //
- //
- //
- // ); + useEffect(() => { + if (!checkToken) { + async function doLogin() { + try { + await LoginApi.login({ userId, password }); + window.location.href = "/map"; + } catch (err) { + console.error("로그인 실패", err); + } + } + doLogin(); + } else { + router.push("/map"); + } + }, []); } diff --git a/apps/sn/package.json b/apps/sn/package.json index 95ec8f3e9..85e600dbb 100644 --- a/apps/sn/package.json +++ b/apps/sn/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "next dev -p 3002", "build": "next build", - "start": "next start", + "start": "next start -p 3002", "lint": "next lint" }, "dependencies": { @@ -18,7 +18,6 @@ "@radix-ui/react-label": "^2.1.2", "@radix-ui/react-slot": "^1.1.2", "@tanstack/react-query": "^5.67.1", - "@tanstack/react-query-devtools": "^5.75.5", "@tanstack/react-table": "^8.21.2", "axios": "^1.8.1", "chart.js": "^4.4.8", diff --git a/apps/sn/src/entities/auth/lib/auth-wrapper.tsx b/apps/sn/src/entities/auth/lib/auth-wrapper.tsx index 4c4ce3645..f0710e249 100644 --- a/apps/sn/src/entities/auth/lib/auth-wrapper.tsx +++ b/apps/sn/src/entities/auth/lib/auth-wrapper.tsx @@ -7,9 +7,7 @@ import type { IUserInfo } from "@/shared/store"; import { useUserStore } from "@/shared/lib"; import { ENDPOINT, AUTH_USER_ID } from "@/shared/config"; import { getCookie } from "@/shared/lib"; -import axios from "axios"; import { LoginApi } from "../api/login-service"; -import { tokenManager } from "../lib/token-manager"; const CLAIM_NAME = process.env.NEXT_PUBLIC_CLAIM_NAME || "Authorization"; @@ -18,32 +16,14 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => { const { userInfo, setUserInfo } = useUserStore((state) => state); async function authCheck() { - const checkToken = getCookie(AUTH_USER_ID); - - - if (!checkToken) { - //TODO 나중에 수정해야.... - const userId = "admin1gmail"; - const password = "test1234!"; - await LoginApi.login({ userId, password }); - // window.location.href = "http://dev.onasys.co.kr/auth/login"; - // throw new Error("Missing required authentication tokens"); + const userId = getCookie(AUTH_USER_ID); + if (!userId) { + throw new Error("Missing required authentication tokens"); } - const accessToken = tokenManager.getToken(CLAIM_NAME); - const tokenId = tokenManager.getToken(AUTH_USER_ID); - - const response = await axios.get( + const response = await client.get( `${ENDPOINT.USER_SERVICE.USERS}/info/me`, - { - withCredentials: true, - headers: { - [CLAIM_NAME]: accessToken, - [AUTH_USER_ID]: tokenId ?? "", - }, - }, ); - if (!userInfo) setUserInfo(response.data); } @@ -60,12 +40,7 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => { } catch (refreshError) { console.error("Token refresh failed:", refreshError); setUserInfo(null); - - // TODO 운영에 반영 할때 수정해야..... - // 현재 경로가 로그인 페이지가 아닐 때만 redirect - // if (!pathname.startsWith("/auth/login")) { - // window.location.href = "http://dev.onasys.co.kr/auth/login"; - // } + router.push("/"); } } })(); From b25c60082a5d1a8c435db5e61bfbea4f94f79c9c Mon Sep 17 00:00:00 2001 From: yschoi Date: Thu, 10 Jul 2025 15:01:41 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sn/package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/sn/package.json b/apps/sn/package.json index 85e600dbb..edf69f3f9 100644 --- a/apps/sn/package.json +++ b/apps/sn/package.json @@ -52,3 +52,6 @@ "typescript": "^5" } } + + + From 4a4ec40787b47d085a042c5a40bb115456ff6ade Mon Sep 17 00:00:00 2001 From: yschoi Date: Thu, 10 Jul 2025 15:28:38 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=EA=B0=9C=EB=B0=9C=20=EB=B0=B0=ED=8F=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sn/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sn/package.json b/apps/sn/package.json index edf69f3f9..83e13a8ed 100644 --- a/apps/sn/package.json +++ b/apps/sn/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "next dev -p 3002", "build": "next build", - "start": "next start -p 3002", + "start:sn": "next start -p 3002", "lint": "next lint" }, "dependencies": { From 4f0a445da2d2cdd1d74fb97c7051774bee1da1f2 Mon Sep 17 00:00:00 2001 From: yschoi Date: Thu, 10 Jul 2025 16:52:49 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=EB=B9=8C=EB=93=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/sn/src/entities/auth/lib/auth-wrapper.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sn/src/entities/auth/lib/auth-wrapper.tsx b/apps/sn/src/entities/auth/lib/auth-wrapper.tsx index f0710e249..75744f66e 100644 --- a/apps/sn/src/entities/auth/lib/auth-wrapper.tsx +++ b/apps/sn/src/entities/auth/lib/auth-wrapper.tsx @@ -40,7 +40,7 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => { } catch (refreshError) { console.error("Token refresh failed:", refreshError); setUserInfo(null); - router.push("/"); + //router.push("/"); } } })();