diff --git a/frontend/app/(protected)/_components/navigation.jsx b/frontend/app/(protected)/_components/navigation.jsx
new file mode 100644
index 00000000..4a7bcab3
--- /dev/null
+++ b/frontend/app/(protected)/_components/navigation.jsx
@@ -0,0 +1,85 @@
+//File: frontend/app/(protected)/_components/navigation.jsx
+'use client'; // <-- 1. กำหนดให้ไฟล์นี้เป็น Client Component
+
+import Link from 'next/link';
+import { usePathname } from 'next/navigation';
+import { Home, FileText, Settings, Package2 } from 'lucide-react';
+import { can } from "@/lib/rbac";
+import { cn } from "@/lib/utils";
+import { Card, CardHeader, CardTitle, CardDescription, CardContent } from "@/components/ui/card";
+import { Button } from "@/components/ui/button";
+
+
+export function Navigation({ user }) { // 2. รับข้อมูล user มาจาก props
+ const pathname = usePathname(); // 3. ใช้งาน usePathname ได้แล้ว
+
+ const navLinks = [
+ { href: '/dashboard', label: 'Dashboard', icon: Home },
+ { href: '/correspondences', label: 'Correspondences', icon: FileText },
+ { href: '/drawings', label: 'Drawings', icon: FileText },
+ // ... เพิ่มเมนูอื่นๆ ตามต้องการ
+ ];
+
+ const adminLink = {
+ href: '/admin/users',
+ label: 'Admin',
+ icon: Settings,
+ requiredPermission: 'manage_users'
+ };
+
+ return (
+
+
+
+
+
LCB P3 DMS
+
+ {/* Bell Icon can be here if needed */}
+
+
+
+
+
+
+
+ Need Help?
+ Contact support for any issues or questions.
+
+
+
+
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/frontend/app/(protected)/layout.jsx b/frontend/app/(protected)/layout.jsx
index b12e1c0d..f70acf32 100644
--- a/frontend/app/(protected)/layout.jsx
+++ b/frontend/app/(protected)/layout.jsx
@@ -1,85 +1,91 @@
// frontend/app/(protected)/layout.jsx
-import Link from "next/link";
+// frontend/app/(protected)/layout.jsx
+
+import { cookies, headers } from "next/headers"; // 1. ยังคงใช้ฟังก์ชันฝั่ง Server
import { redirect } from "next/navigation";
-import { usePathname } from 'next/navigation';
-import { cookies, headers } from "next/headers";
-import { can } from "@/lib/rbac";
-import { Home, FileText, Users, Settings } from 'lucide-react'; // เพิ่ม Users, Settings หรือไอคอนที่ต้องการ
+import { Bell, Users } from 'lucide-react';
+
+import { Button } from '@/components/ui/button';
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from '@/components/ui/dropdown-menu';
+
+// 2. Import Navigation Component ที่เราสร้างขึ้นมาใหม่
+import { Navigation } from "./_components/navigation";
export const metadata = { title: "DMS | Protected" };
-const API_BASE = (process.env.NEXT_PUBLIC_API_BASE || "").replace(/\/$/, "");
+const API_BASE = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001";
-async function fetchSessionFromAPI() {
- const cookieStore = await cookies(); // ✅ ต้อง await
- const cookieHeader = cookieStore.toString();
+async function fetchSession() {
+ const cookieStore = cookies();
+ const token = cookieStore.get("access_token")?.value;
- const hdrs = await headers(); // ✅ ต้อง await
- const hostHdr = hdrs.get("host");
- const protoHdr = hdrs.get("x-forwarded-proto") || "https";
+ if (!token) return null;
- const res = await fetch(`${API_BASE}/api/auth/me`, {
- method: "GET",
- headers: {
- Cookie: cookieHeader,
- "X-Forwarded-Host": hostHdr || "",
- "X-Forwarded-Proto": protoHdr,
- Accept: "application/json",
- },
- cache: "no-store",
- });
-
- if (!res.ok) return null;
try {
- const data = await res.json();
- return data?.ok ? data : null;
- } catch {
+ const res = await fetch(`${API_BASE}/api/auth/me`, {
+ headers: { Authorization: `Bearer ${token}` },
+ cache: "no-store",
+ });
+
+ if (!res.ok) return null;
+ return await res.json();
+ } catch (error) {
+ console.error("Failed to fetch session:", error);
return null;
}
}
+
export default async function ProtectedLayout({ children }) {
- const session = await fetchSessionFromAPI();
- if (!session) {
- redirect("/login?next=/dashboard");
+ // 3. ดึงข้อมูล Session บน Server
+ const session = await fetchSession();
+
+ // ถ้าไม่มี session หรือ user ให้ redirect ไปหน้า login
+ if (!session?.user) {
+ redirect("/login");
}
- const { user } = session;
return (
-
-