Auto-logout users when page is closed
- Create LogoutOnUnload component that triggers logout on page close - Uses beforeunload/unload events with navigator.sendBeacon() for reliability - Create /api/logout endpoint that clears both admin and customer sessions - Add LogoutOnUnload to root layout so it runs on all pages - Works for both admin and customer users Behavior: - When user closes browser tab/window, logout happens automatically - Session cookies are cleared via API endpoint - Improves security by preventing session hijacking from closed windows Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
a2908e8ae1
commit
3aa2b730bc
@@ -0,0 +1,14 @@
|
||||
import { cookies } from 'next/headers';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function POST() {
|
||||
const cookieStore = await cookies();
|
||||
|
||||
// Clear admin session
|
||||
cookieStore.delete('adminSession');
|
||||
|
||||
// Clear customer session
|
||||
cookieStore.delete('session');
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
Reference in New Issue
Block a user