NextJS + Prisma + Planetscale Data Not Updating

17 Views Asked by At

I have a nextjs13 application with prisma/planetscale for handling my data. My query seems to be working locally, but when testing live on a deployed site, the query updates the field (i see it updated in prisma studio) but the client side does not reflect it.

Here is the function in my jsx file running:

const ActionCell = ({ row }: { row: any }) => {
  const status = row.original;
  const router = useRouter();
  const [selectedStatus, setSelectedStatus] = useState("");

 const updateStatus = async (selectedStatus: any) => {
    setSelectedStatus(selectedStatus);
    const res = await fetch("/api/contacts", {
      method: "PUT",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        id: status.id,
        selectedStatus: selectedStatus,
      }),
    });
    console.log(res);
    router.refresh();
  };

Here is my api file

import prisma from "@/lib/prisma";

export async function PUT(request) {
  // 405 now allowed
  if (request.method !== "PUT") {
    return new Response("Method not allowed", { status: 405 });
  }

  const body = await request.json();
  console.log(body);

  try {
    await prisma.contacts.update({
      where: { id: body.id },
      data: { status: body.selectedStatus },
    });
  } catch (error) {
    console.error("Error creating user: ", error);
    return new Response(error);
  }
  return new Response("Succcess", {
    status: 200,
  });
}

I am seeing the successful status on both local and live, but again no changes are actually happening on the live site, just locally. I have verified the API key on my vercel server.

0

There are 0 best solutions below