Ayush Goyal
Ayush Goyal11mo 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 Goyal11mo ago
i guess whenever we are defining a saperate proccesor we have to use "use"
NeoBean
NeoBean11mo 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 Goyal10mo ago
thank you