Next.js Discord

Discord Forum

Server Actions Error

Unanswered
Spectacled Caiman posted this in #help-forum
Open in Discord
Spectacled CaimanOP
I have this code:
  const { installers } = data;
    const formattedInstallers = installers.filter((x) => x.name !== "");

    if (!formattedInstallers) return;

    const dbPromise = addNewCustomer({
      ...data,
      installers: formattedInstallers,
    });

    toast.promise(dbPromise, {
      loading: "Saving to the database",
      success: "Successfully added a new customer",
      error: "Something went wrong while adding a customer",
    });


Server Actions File:
"use server";

import { db } from "@/lib/db";
import { CustomerCredentials } from "@/lib/validators/new-customer";

export async function addNewCustomer({ ...data }: CustomerCredentials) {
  try {
    db.customer.create({
      data: {
        ...data,
        installers: {
          set: data.installers,
        },
      },
    });
  } catch (err) {
    console.error(err);
  }
}


But for some reason I don't get an error and it does not get created in the database.

3 Replies

@riský is this prisma? if so can you try `await`ing the database create to maybe see the error
Spectacled CaimanOP
I tried too, but I got the same result