import { ActionFunction, json } from "@remix-run/node";
import { withAuth } from "~/auth/withAuth";
import { activeProjectCookie } from "~/services/activeProject.server";

export const action: ActionFunction = withAuth(async ({ request }) => {
  const { projectId } = await request.json();
  const cookieHeader = await activeProjectCookie.serialize(projectId);

  return json(
    { success: true },
    {
      headers: {
        "Set-Cookie": cookieHeader,
      },
    },
  );
});
