import{authenticate,clearSessionCookie,getSession,sessionCookie}from"../../auth-server";export async function GET(request:Request){const s=await getSession(request);return s?Response.json({user:s}):Response.json({user:null},{status:401})}export async function POST(request:Request){const{username="",password=""}=await request.json() as{username?:string;password?:string},s=await authenticate(String(username).trim(),String(password));if(!s)return Response.json({error:"Nama pengguna atau kata sandi salah."},{status:401});return new Response(JSON.stringify({user:s}),{headers:{"Content-Type":"application/json","Set-Cookie":await sessionCookie(s)}})}export async function DELETE(){return new Response(JSON.stringify({ok:true}),{headers:{"Content-Type":"application/json","Set-Cookie":clearSessionCookie()}})}
