ERP-node/frontend/app/(main)/admin/page.tsx

92 lines
2.7 KiB
TypeScript
Raw Normal View History

2025-08-21 09:41:46 +09:00
"use client";
import { useEffect, useState } from "react";
2025-08-21 09:41:46 +09:00
/**
* ()
*
2025-08-21 09:41:46 +09:00
*/
export default function AdminPage() {
const [tokenInfo, setTokenInfo] = useState<any>({});
const [isAuthorized, setIsAuthorized] = useState<boolean | null>(null);
useEffect(() => {
console.log("=== AdminPage 시작 ===");
const token = localStorage.getItem("authToken");
console.log("localStorage 토큰:", token ? "존재" : "없음");
const info = {
hasToken: !!token,
tokenLength: token ? token.length : 0,
tokenStart: token ? token.substring(0, 30) + "..." : "없음",
currentUrl: window.location.href,
timestamp: new Date().toISOString(),
};
setTokenInfo(info);
console.log("토큰 정보:", info);
if (!token) {
console.log("토큰이 없음 - 로그인 페이지로 이동");
setIsAuthorized(false);
// 3초 후 리다이렉트
setTimeout(() => {
window.location.href = "/login";
}, 3000);
return;
}
// 토큰이 있으면 인증된 것으로 간주
console.log("토큰 존재 - 인증된 것으로 간주");
setIsAuthorized(true);
}, []);
if (isAuthorized === null) {
return (
<div className="p-6">
<h1 className="mb-4 text-2xl font-bold"> ...</h1>
</div>
);
}
if (isAuthorized === false) {
return (
<div className="p-6">
<h1 className="mb-4 text-2xl font-bold text-red-600"> </h1>
<p> . 3 .</p>
<div className="mt-4 rounded bg-yellow-100 p-4">
<h2 className="mb-2 font-semibold"> </h2>
<pre className="text-xs">{JSON.stringify(tokenInfo, null, 2)}</pre>
</div>
</div>
);
}
return (
<div className="p-6">
<h1 className="mb-4 text-2xl font-bold"> </h1>
<p className="mb-4 text-green-600"> ! .</p>
<div className="mb-4 rounded bg-green-100 p-4">
<h2 className="mb-2 font-semibold"> </h2>
<pre className="text-xs">{JSON.stringify(tokenInfo, null, 2)}</pre>
</div>
<div className="rounded bg-blue-100 p-4">
<h2 className="mb-2 font-semibold"> </h2>
<p> .</p>
<button
onClick={() => {
alert("관리자 기능이 정상 작동합니다!");
}}
className="mt-2 rounded bg-blue-500 px-4 py-2 text-white hover:bg-blue-600"
>
</button>
</div>
</div>
);
2025-08-21 09:41:46 +09:00
}