| |
| import { redirect } from 'next/navigation'; |
| import { cookies } from 'next/headers'; |
| import Navigation from '@/components/organisms/Navigation'; |
| import { API_BASE_URL } from '@/lib/constants/api'; |
|
|
| export default async function DashboardLayout({ |
| children, |
| }: { |
| children: React.ReactNode; |
| }) { |
| |
| const cookieStore = cookies(); |
| const token = cookieStore.get('access_token')?.value; |
|
|
| |
| if (!token) { |
| redirect('/login'); |
| } |
|
|
| |
| |
| try { |
| const response = await fetch(`${API_BASE_URL}/users/me`, { |
| headers: { |
| Authorization: `Bearer ${token}`, |
| }, |
| |
| cache: 'no-store', |
| }); |
|
|
| if (!response.ok) { |
| |
| redirect('/login'); |
| } |
|
|
| |
| const user = await response.json(); |
|
|
| return ( |
| <div className="flex h-screen overflow-hidden bg-slate-50"> |
| {/* Navigation is likely a Client Component ("use client") |
| that handles active states, but we can pass server-fetched user data to it |
| */} |
| <Navigation user={user} /> |
| |
| {/* Main Content Area for the 10 Research Phases */} |
| <main className="flex-1 overflow-y-auto overflow-x-hidden pt-16 md:pt-0"> |
| <div className="mx-auto max-w-7xl px-4 py-8 sm:px-6 md:px-8"> |
| {children} |
| </div> |
| </main> |
| </div> |
| ); |
| } catch (error) { |
| |
| console.error('Backend connection failed:', error); |
| redirect('/login'); |
| } |
| } |
|
|