andreas
andreas
TtRPC
Created by andreas on 5/24/2025 in #❓-help
public/protectedProcedure returns `any` in client usage
5 replies
TtRPC
Created by andreas on 5/24/2025 in #❓-help
public/protectedProcedure returns `any` in client usage
right now the only workaround to this is to define all my routers directly where my AppRouter lives (i.e.:
export const rootRouter = t.router({
app: t.router({
helloWorld: t.router({ ... }),
// instead of
// helloWorld: helloWorldRouter
}),
});
export const rootRouter = t.router({
app: t.router({
helloWorld: t.router({ ... }),
// instead of
// helloWorld: helloWorldRouter
}),
});
here are my public/privateProcedure(s):
export const publicProcedure = t.procedure;
export const protectedProcedure = t.procedure.use((opts) => {
const { ctx } = opts;

if (!ctx.session) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You are not signed in.",
});
}

return opts.next({ ctx });
});
export const publicProcedure = t.procedure;
export const protectedProcedure = t.procedure.use((opts) => {
const { ctx } = opts;

if (!ctx.session) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You are not signed in.",
});
}

return opts.next({ ctx });
});
here is a router using these procedures:
export const helloWorldRouter = t.router({
getName: publicProcedure.input(z.string().min(2)).mutation(async (opts) => {
return HelloWorldModule.build().getName(opts);
}),
protected_getName: protectedProcedure
.input(z.string().min(2))
.mutation(async (opts) => {
return HelloWorldModule.build().getName(opts);
}),
});
export const helloWorldRouter = t.router({
getName: publicProcedure.input(z.string().min(2)).mutation(async (opts) => {
return HelloWorldModule.build().getName(opts);
}),
protected_getName: protectedProcedure
.input(z.string().min(2))
.mutation(async (opts) => {
return HelloWorldModule.build().getName(opts);
}),
});
here's the client code where the types are incorrectly returned as any
export default function LoginForm() {
const router = useRouter();
const session = authClient.useSession();

const { app } = useTRPC();
const getNameQuery = useMutation(app.helloWorld.getName.mutationOptions());
// ^^^^
// is typeof any but should be whatever type `t.procedure` is
const protected_getNameQuery = useMutation(app.helloWorld.protected_getName.mutationOptions());
// ^^^^
// is typeof any but should be whatever type `t.procedure` is
export default function LoginForm() {
const router = useRouter();
const session = authClient.useSession();

const { app } = useTRPC();
const getNameQuery = useMutation(app.helloWorld.getName.mutationOptions());
// ^^^^
// is typeof any but should be whatever type `t.procedure` is
const protected_getNameQuery = useMutation(app.helloWorld.protected_getName.mutationOptions());
// ^^^^
// is typeof any but should be whatever type `t.procedure` is
5 replies