import { NextResponse, type NextRequest } from 'next/server';

import { PORTAL_COOKIE } from '@/lib/portal/auth';

export async function POST(req: NextRequest): Promise<NextResponse> {
  // Build the redirect from the request URL so we stay on whatever host
  // the user is actually browsing from (localhost, LAN IP, prod domain).
  // Reading env.APP_URL here used to redirect phone-on-LAN users back
  // to localhost.
  const response = NextResponse.redirect(new URL('/portal/login', req.url));

  response.cookies.delete(PORTAL_COOKIE);

  return response;
}
