NicolasN
tRPC2y ago
2 replies
Nicolas

No "mutation"-procedure on path

Hello all,

I am using the latest version of TRPC on my client and server. I am using React Query on my client and AWS Lambda on my server side.

When trying to perform a test mutation:
export default function () {
    const organizationCreate = trpc.insert_superUser.useMutation();
    const insertTestOrg = async () => {
        const repsonse = organizationCreate.mutate({
            name: "Test Organization",
            description: "Test Description",            
        }, {
            onError: (error) => {
                console.log("Error", error);
            }
        })
    }
    return (<div>
        <Button variant="primary" onClick={() => insertTestOrg()}>Button</Button>
    </div>)
}


I get the following error Error TRPCClientError: No "mutation"-procedure on path "insert_superUser"

I am using a Meta to make sure only users of a specified role can call certain functions, like so:
interface Meta {
    role: Role;
}
const t = initTRPC.context<Context>().meta<Meta>().create({
  defaultMeta: {
    role: Role.OrganizationUser
  }
});

export const authRoleProcedure = t.procedure.use(async (opts) => {  
  const { meta, next, ctx } = opts;
  if (!meta?.role) {
    throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: 'Role not defined in meta' });
  }
  if (!ctx.user) {
    throw new TRPCError({ code: 'BAD_REQUEST', message: 'User not defined in context'});
  }
  if (ctx.user.role > meta.role) {
    throw new TRPCError({ code: 'UNAUTHORIZED', message: `User does not have the required role. Required: ${meta.role}, User: ${ctx.user.role}`});
  }
  console.log('User has the required role')
  return next();
});

export const router = t.router;
Was this page helpful?