From 3bcdb6379f781ff6fc373e8a6089e6b05559285b Mon Sep 17 00:00:00 2001 From: Marcos Fargas Date: Mon, 21 Sep 2026 02:20:09 +0200 Subject: [PATCH] feat(auth): add /login page, session middleware, role-based navigation and logout --- src/app/auth/actions.ts | 10 +++ src/app/dashboard/layout.tsx | 84 +++++++++++++----- src/app/login/page.tsx | 168 +++++++++++++++++++++++++++++++++++ src/app/page.tsx | 12 ++- src/middleware.ts | 91 +++++++++++++++---- 5 files changed, 323 insertions(+), 42 deletions(-) create mode 100644 src/app/auth/actions.ts create mode 100644 src/app/login/page.tsx 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 */} -