29 lines
653 B
TypeScript
29 lines
653 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import { cookies } from 'next/headers';
|
|
|
|
export async function POST() {
|
|
try {
|
|
const response = NextResponse.json(
|
|
{ message: 'Logout berhasil' },
|
|
{ status: 200 }
|
|
);
|
|
|
|
// Clear the token cookie with additional security options
|
|
response.cookies.set('token', '', {
|
|
expires: new Date(0),
|
|
path: '/',
|
|
httpOnly: true,
|
|
secure: false,
|
|
sameSite: 'lax'
|
|
});
|
|
|
|
return response;
|
|
} catch (error) {
|
|
console.error('Logout error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Terjadi kesalahan saat logout' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|