Augustin Sorel
Augustin Sorel5mo ago

Bug: Setting up cookies not woring when using .input in nextjs

Hey guys I am trying to set up a cookie with nextjs 14 and trpc. However my cookie is only being set when I am not using the .input method. I have attached a video showing this. reproduction steps: * pnpm create t3-app * added cookies().set("hello", "world"); in the postRouter * the cookie is not being set. Here is the code if you prefer:
create: publicProcedure
.input(z.object({ name: z.string() })) // when commenting this, setting up cookies are working as expected
.mutation(async ({ input }) => {
cookies().set("hello", "world");

// simulate a slow db call
await new Promise((resolve) => setTimeout(resolve, 1000));

post = { id: post.id + 1, name: input.name };
return post;
}),
create: publicProcedure
.input(z.object({ name: z.string() })) // when commenting this, setting up cookies are working as expected
.mutation(async ({ input }) => {
cookies().set("hello", "world");

// simulate a slow db call
await new Promise((resolve) => setTimeout(resolve, 1000));

post = { id: post.id + 1, name: input.name };
return post;
}),
1 Reply
epicmau5time
epicmau5time3mo ago
Did you ever solve this? I have the same issue