Index not found error even when the index is defined in the schema
Hello,
I'm using the Local install of Convex + Better Auth (https://convex-better-auth.netlify.app/features/local-install#adding-custom-indexes) and trying to run a query using and index, convex throws the following error:
Uncaught Error: Uncaught Error: Index member.userId not found.
at handler (../../convex/betterAuth/member.ts:15:1)
The schema has the index and, strangely, the query works is I run it directly in the dashboard. I attach the schema and the query. Any light on this would be very helpful.
Thanks
import { v } from 'convex/values'
import { query } from './_generated/server'
import { vv } from './helpers'
/betterAuth/member.ts
import { v } from 'convex/values'
import { query } from './_generated/server'
import { vv } from './helpers'
export const listByUserId = query({
args: {
userId: v.string(),
},
returns: vv.array(vv.doc('member')),
handler: async (ctx, { userId }) => {
return await ctx.db
.query('member')
.withIndex('userId', (q) => q.eq('userId', userId))
.collect()
},
})
/betterAuth/schema.ts
...
member: defineTable({
organizationId: v.string(),
userId: v.string(),
role: v.string(),
createdAt: v.number(),
})
.index("organizationId", ["organizationId"])
.index("userId", ["userId"])
.index("role", ["role"]),
...Local Install | Convex + Better Auth
Own your auth.
1 Reply
For reference, I've found the problem. I was using "api.betterAuth.member.listByUserId instead" of "components.betterAuth.member.listByUserId". "components" should be used and no "api" for accessing the components functions