From 781a7c1be369fe097a2bd7f98f16812d29b94345 Mon Sep 17 00:00:00 2001 From: Randa Firman Putra Date: Mon, 8 Dec 2025 02:01:25 +0700 Subject: [PATCH] logout secure --- app/api/auth/logout/route.ts | 6 +++--- components/ui/Navbar.tsx | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/api/auth/logout/route.ts b/app/api/auth/logout/route.ts index 4190509..2f6304e 100644 --- a/app/api/auth/logout/route.ts +++ b/app/api/auth/logout/route.ts @@ -7,12 +7,12 @@ export async function POST() { // Clear the session cookie response.cookies.set('user_session', '', { - httpOnly: true, - secure: process.env.NODE_ENV === 'production', + httpOnly: true, + secure: false, // Set to false to allow HTTP (for Coolify deployment) sameSite: 'lax', maxAge: 0, // Expire immediately path: '/', - }); + }); return response; } diff --git a/components/ui/Navbar.tsx b/components/ui/Navbar.tsx index f301853..0ceafcd 100644 --- a/components/ui/Navbar.tsx +++ b/components/ui/Navbar.tsx @@ -87,8 +87,10 @@ const Navbar = () => { if (response.ok) { setUser(null); showSuccess("Berhasil!", "Anda telah keluar dari sistem"); - // Redirect to root page after successful logout - router.push('/'); + // Redirect to root page after successful logout - using window.location for hard redirect + setTimeout(() => { + window.location.href = '/'; + }, 500); // Small delay to show toast notification } } catch (error) { console.error('Logout error:', error);