Spaces:
Build error
Build error
File size: 1,150 Bytes
17cf14d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 'use client'
import { usePathname, useRouter } from 'next/navigation'
import { useAuth } from '@/lib/auth'
import Sidebar from './Sidebar'
import { useEffect } from 'react'
export default function LayoutWrapper({ children }: { children: React.ReactNode }) {
const pathname = usePathname()
const router = useRouter()
const { user, isLoading } = useAuth()
const isLoginPage = pathname === '/login'
useEffect(() => {
if (!isLoading && !user && !isLoginPage) {
router.push('/login')
}
}, [user, isLoading, isLoginPage, router])
// Show login page without sidebar
if (isLoginPage) {
return children
}
// Show loading or redirect
if (isLoading) {
return (
<div className="min-h-screen flex items-center justify-center bg-slate-900">
<div className="text-white text-lg">Loading...</div>
</div>
)
}
// Show main app layout
if (user) {
return (
<div className="flex min-h-screen">
<Sidebar />
<main className="flex-1 ml-64">
{children}
</main>
</div>
)
}
return null
}
|