Mitchell Magro 7851a6fa24 Added Logout
2025-07-23 07:37:39 +02:00

25 lines
760 B
TypeScript

// app/api/auth/logout/route.ts
import { NextResponse } from "next/server";
import { cookies } from "next/headers";
// This is your DELETE handler for the logout endpoint
export async function DELETE(request: Request) {
try {
// Clear the authentication cookie.
// This MUST match the name of the cookie set during login.
// In your login handler, the cookie is named "auth_token".
cookies().delete("auth_token");
return NextResponse.json(
{ success: true, message: "Logged out successfully" },
{ status: 200 }
);
} catch (error) {
console.error("Logout API error:", error);
return NextResponse.json(
{ success: false, message: "Internal server error during logout" },
{ status: 500 }
);
}
}