Ayush Goyal
Ayush Goyal2y ago

what is "use" keyword

const baseProcedure = t.procedure
.input(z.object({ townName: z.string() }))
.use((opts) => {
const input = opts.input;

const input: {
townName: string;
}

console.log(`Handling request with user from: ${input.townName}`);

return opts.next();
});
const baseProcedure = t.procedure
.input(z.object({ townName: z.string() }))
.use((opts) => {
const input = opts.input;

const input: {
townName: string;
}

console.log(`Handling request with user from: ${input.townName}`);

return opts.next();
});
what is this usekeyword any place i can read about it
3 Replies
Ayush Goyal
Ayush GoyalOP2y ago
i guess whenever we are defining a saperate proccesor we have to use "use"
NeoBean
NeoBean2y ago
Middlewares | tRPC
You are able to add middleware(s) to a procedure with the t.procedure.use() method. The middleware(s) will wrap the invocation of the procedure and must pass through its return value.
Ayush Goyal
Ayush GoyalOP2y ago
thank you