37 lines
931 B
TypeScript
37 lines
931 B
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
import { redirect } from 'next/navigation'
|
|
import { createClient } from '@/lib/supabase/server'
|
|
import Sidebar from '@/components/dashboard/Sidebar'
|
|
|
|
export default async function DashboardLayout({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode
|
|
}) {
|
|
const supabase = await createClient()
|
|
const db = supabase as any
|
|
|
|
const { data: { user }, error } = await supabase.auth.getUser()
|
|
if (error || !user) {
|
|
redirect('/login')
|
|
}
|
|
|
|
const { data: profile } = await db
|
|
.from('profiles')
|
|
.select('username, role')
|
|
.eq('id', user.id)
|
|
.single()
|
|
|
|
return (
|
|
<div className="flex min-h-screen bg-background">
|
|
<Sidebar
|
|
username={profile?.username ?? user.email?.split('@')[0] ?? 'Utilisateur'}
|
|
role={profile?.role ?? 'formateur'}
|
|
/>
|
|
<main className="flex-1 overflow-auto">
|
|
{children}
|
|
</main>
|
|
</div>
|
|
)
|
|
}
|