rustclan
rustclan16mo ago

trpc receiving undefined

Hello, I am having a few problems with one of my TRPC endpoints not recieving the data sent through a webhook body
export const voteRouter = createTRPCRouter({
voteCreate: publicProcedure
.input(
z.object({
user: z.string(),
type: z.string(),
query: z.string(),
isWeekend: z.boolean().nullable().optional(),
bot: z.string(),
})
).mutation(async ({ ctx, input }) => {
console.log(input);
}),
});
export const voteRouter = createTRPCRouter({
voteCreate: publicProcedure
.input(
z.object({
user: z.string(),
type: z.string(),
query: z.string(),
isWeekend: z.boolean().nullable().optional(),
bot: z.string(),
})
).mutation(async ({ ctx, input }) => {
console.log(input);
}),
});
however, i get this error when trpc parses the data
site:dev: :x: tRPC failed on vote.voteCreate: [
site:dev: {
site:dev: "code": "invalid_type",
site:dev: "expected": "object",
site:dev: "received": "undefined",
site:dev: "path": [],
site:dev: "message": "Required"
site:dev: }
site:dev: ]
site:dev: :x: tRPC failed on vote.voteCreate: [
site:dev: {
site:dev: "code": "invalid_type",
site:dev: "expected": "object",
site:dev: "received": "undefined",
site:dev: "path": [],
site:dev: "message": "Required"
site:dev: }
site:dev: ]
I'm not entirely sure why this says received undefined, when the request.body outputs:
{
user: '123',
type: 'upvote',
query: '',
isWeekend: false,
bot: '123'
}
{
user: '123',
type: 'upvote',
query: '',
isWeekend: false,
bot: '123'
}
export default createNextApiHandler({
router: appRouter,
createContext: createTRPCContext,
onError: async (opts) => {
const { error, path, req } = opts;
console.log(req.body);
export default createNextApiHandler({
router: appRouter,
createContext: createTRPCContext,
onError: async (opts) => {
const { error, path, req } = opts;
console.log(req.body);
root:
export const appRouter = createTRPCRouter({
vote: voteRouter,
});
export const appRouter = createTRPCRouter({
vote: voteRouter,
});
insomnia request:
No description
1 Reply
epistol
epistol16mo ago
Same Looks like you need const { json, meta } = superjson.serialize(object); to use superjson where you send your data