Type Inference Issue with Custom Auth Wrappers
any. I'm using convex-helpers to create custom auth wrappers, but the types aren't being inferred correctly in my Next.js frontend.Example Simple Custom Wrapper
// In convex/core/auth/index.ts
export const withAuthQuery = customQuery(
query,
customCtx(async (ctx) => {
const identity = await ctx.auth.getUserIdentity();
if (!identity) throw new Error("Not authenticated");
const user = await ctx.db
.query("users")
.withIndex("by_user_id", q => q.eq("userId", identity.subject))
.unique();
if (!user) throw new Error("User not found");
return { user };
}),
);
Example Function Using the Wrapper
// In convex/features/users/public.ts
export const getProfile = withAuthQuery({
args: {},
handler: async (ctx) => {
// ctx.user is available from the wrapper
return ctx.user;
}
});
The Problem
In the Next.js frontend:
// In Next.js - types show as 'any'
import { api } from "@app/convex/_generated/api";
import { useQuery } from "convex/react";
// No type inference - shows as any
const profile = useQuery(api.features.users.public.getProfile);
// ^-- type of getProfile when I hover over it is any instead of the actual user type. Autocomplete works for everything up until the getProfile
The generated _generated/api.js contains:
export const api = anyApi;
Which doesn't preserve type information for custom functions. Question: Is there a way to get proper type inference for functions created with convex-helpers' custom wrappers? The types work fine within the Convex package, but are lost when imported in the frontend.
