Change Alur Aplikasi

This commit is contained in:
Randa Firman Putra
2025-07-14 15:07:33 +07:00
parent db82b40a6b
commit 6d86e1ca2f
53 changed files with 6109 additions and 964 deletions

View File

@@ -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',
}
});
}