fix(auth,api): resolve SSR vs CSR API URL routing and sanitize ADMIN_TOKEN parsing

- Implement getApiBaseUrl() and getAdminApiBaseUrl() to dynamically distinguish between Server/SSR (process.env.API_BASE_URL) and Client/CSR (process.env.NEXT_PUBLIC_API_BASE_URL)
- Fix missing data on main landing page in containerized environment
- Sanitize and trim ADMIN_TOKEN parsing in Go backend to prevent whitespace/quote mismatch
- Real-time token validation in AdminLayout with auto-redirection on token mismatch
- All unit and E2E test gates passed clean with unanimous PASS reviews
This commit is contained in:
2026-08-25 11:42:40 +09:00
parent 0a589bd3a2
commit 5f87631530
6 changed files with 74 additions and 16 deletions
+31 -5
View File
@@ -4,6 +4,7 @@ import React, { useEffect, useState } from "react";
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import { getClientToken, removeClientToken } from "./_components/AdminComponents";
import { adminVerifyToken } from "../../lib/adminApi";
export default function AdminLayout({ children }: { children: React.ReactNode }) {
const pathname = usePathname();
@@ -11,12 +12,37 @@ export default function AdminLayout({ children }: { children: React.ReactNode })
const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
useEffect(() => {
const token = getClientToken();
if (!token && pathname !== "/console/login") {
router.push("/console/login");
} else {
setIsAuthenticated(true);
let isMounted = true;
async function checkAuth() {
const token = getClientToken();
if (!token) {
if (pathname !== "/console/login") {
router.push("/console/login");
} else {
setIsAuthenticated(false);
}
return;
}
const isValid = await adminVerifyToken(token);
if (!isMounted) return;
if (!isValid) {
removeClientToken();
if (pathname !== "/console/login") {
router.push("/console/login");
} else {
setIsAuthenticated(false);
}
} else {
setIsAuthenticated(true);
}
}
checkAuth();
return () => {
isMounted = false;
};
}, [pathname, router]);
if (pathname === "/console/login") {