35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
"use client";
|
|
import { LoginApi } from "@/src/entities/auth";
|
|
import { useEffect } from "react";
|
|
import { AUTH_USER_ID } from "@/src/shared/config";
|
|
import { getCookie } from "@/src/shared/lib/cookie";
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
|
export default function Home() {
|
|
const router = useRouter();
|
|
const checkToken = getCookie(AUTH_USER_ID);
|
|
|
|
useEffect(() => {
|
|
|
|
if (!checkToken) {
|
|
// 외부 URL로 이동해야 할 경우 location.replace를 사용합니다.
|
|
if (window.location.hostname.includes("hasuon.or.kr")) {
|
|
location.replace(process.env.NEXT_PUBLIC_CM_LOGIN_PAGE_URL||'/pages/dashboard');
|
|
return; // 페이지 이동 후에는 더 이상 로직을 실행하지 않습니다.
|
|
}
|
|
|
|
async function doLogin() {
|
|
try {
|
|
await LoginApi.login({ userId: "CLEANWATER", password: "gktneh12!@" });
|
|
router.push("/pages/dashboard"); // location.href 대신 router.push 사용
|
|
} catch (err) {
|
|
console.error("로그인 실패", err);
|
|
}
|
|
}
|
|
doLogin();
|
|
} else {
|
|
router.push("/pages/dashboard");
|
|
}
|
|
}, []);
|
|
} |