Change Alur Aplikasi
This commit is contained in:
@@ -1,28 +1,29 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
const response = NextResponse.json(
|
||||
{ message: 'Logout berhasil' },
|
||||
{ status: 200 }
|
||||
);
|
||||
const response = NextResponse.json({
|
||||
message: 'Logout berhasil',
|
||||
});
|
||||
|
||||
// Clear the token cookie with additional security options
|
||||
response.cookies.set('token', '', {
|
||||
expires: new Date(0),
|
||||
path: '/',
|
||||
// Clear the session cookie
|
||||
response.cookies.set('user_session', '', {
|
||||
httpOnly: true,
|
||||
secure: false,
|
||||
sameSite: 'lax'
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
sameSite: 'lax',
|
||||
maxAge: 0, // Expire immediately
|
||||
path: '/',
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('Logout error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Terjadi kesalahan saat logout' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle OPTIONS request for CORS
|
||||
export async function OPTIONS() {
|
||||
return NextResponse.json({}, {
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'POST, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user