Rasmus
TTCTheo's Typesafe Cult
•Created by Rasmus on 10/23/2023 in #questions
Submit server form action with tRPC in T3
In theos most recent video on server actions in nextjs using the T3 stack, he gets an error https://youtu.be/PmBfq-SpzCU?si=kq1IhqH6-iptkh8v&t=508. I didn't catch what he did to solve it. I'm trying to do something similar. In my case, i just want to create a db entry using tRPC as a server action.
This function is used as an action in a form.
const handleAddStore = async () => {
"use server";
await api.store.create.mutate();
revalidatePath("/store");
};
This is the trpc procedure.
create: protectedProcedure.mutation(async ({ ctx }) =>
createNewStore(ctx.session.user.id, ctx.db, "Ny affär"),
),
I get this error:
Unhandled Runtime Error
Error: fetch failed
Call Stack
TRPCClientError.from
node_modules@trpc\client\dist\TRPCClientError-0de4d231.mjs (37:15)
from
node_modules@trpc\client\dist\httpBatchLink-204206a5.mjs (200:55)2 replies