diff --git a/src/app/auth/actions.ts b/src/app/auth/actions.ts new file mode 100644 index 0000000..3153b7b --- /dev/null +++ b/src/app/auth/actions.ts @@ -0,0 +1,10 @@ +'use server'; + +import { createClient } from '@/lib/supabase/server'; +import { redirect } from 'next/navigation'; + +export async function logoutAction() { + const supabase = await createClient(); + await supabase.auth.signOut(); + redirect('/login'); +} diff --git a/src/app/dashboard/layout.tsx b/src/app/dashboard/layout.tsx index 6abe019..8cb7d13 100644 --- a/src/app/dashboard/layout.tsx +++ b/src/app/dashboard/layout.tsx @@ -6,18 +6,30 @@ import { FolderGit2, Bot, ShieldCheck, - Layers + Layers, + LogOut, + UserCheck } from 'lucide-react'; +import { createClient } from '@/lib/supabase/server'; +import { logoutAction } from '@/app/auth/actions'; -export default function DashboardLayout({ +export default async function DashboardLayout({ children, }: { children: React.ReactNode; }) { + const supabase = await createClient(); + const { data: { user } } = await supabase.auth.getUser(); + + const role = user?.user_metadata?.role || user?.app_metadata?.role || 'client'; + const company = user?.user_metadata?.company || '4Ventures Central'; + const email = user?.email || 'usuario@4ventures.es'; + const isAgency = role === 'admin' || role === 'team'; + return (
{/* Sidebar */} -