David AlonsoD
Convex Communityโ€ข2y agoโ€ข
4 replies
David Alonso

Best way to call an `authenticatedQuery` from another `authenticatedQuery`

I've defined a customQuery as follows:
export const authenticatedQuery = customQuery(
  queryRaw, // The base function we're extending
  {
    args: {
      // This type makes sure we can't just forget to pass the clerkOrgId
      clerkOrgId: v.string(),
      userTokenIdentifier: v.optional(v.string()),
    },
    input: async (ctx, args) => {
      const { user, workspace } = await enhanceClientAuthContext(
        ctx,
        args.clerkOrgId,
        args.userTokenIdentifier
      );
      // Authorization checks should be done on the specific query function based on the info added to the context

      return { ctx: { user, workspace }, args: { ...args } };
    },
  }
);


This works great in cases when I call this query from the client, but if I want to call this query from another authenticatedQuery it feels a bit clunky and double work is required to create the custom context, when ideally it could just be passed around.

Looking for advice on the cleanest way to do this ๐Ÿ™
Was this page helpful?