Coop
Coop16mo ago

Forced router input?

I have a user route which has routes like get, delete, create etc. Some of the routes I require extra data but in all of them, my input contains:
id: z.string()
id: z.string()
I also call this code in all my routes:
const user = await db.query.users.findFirst({
where: eq(users.id, input.id),
})
const user = await db.query.users.findFirst({
where: eq(users.id, input.id),
})
Is there a way to create a wrapper or middleware that implements route logic like .input() but allows for other routes?
2 Replies
Alex / KATT 🐱
Alex / KATT 🐱16mo ago
Define Procedures | tRPC
A procedure is a function which is exposed to the client, it can be one of:
Coop
CoopOP16mo ago
Yea I saw that
const userIdProcedure = publicProcedure.input(
z.object({
id: z.string(),
})
)
const userIdProcedure = publicProcedure.input(
z.object({
id: z.string(),
})
)
Trpc is actually blowing my mind. This library is as cool as zod

Did you find this page helpful?