oscklmO
Convex Community3y ago
3 replies
oscklm

Issue with type inference using convex-lucia-auth-demo in a mono repo

I've been playing around with the convex-lucia-auth-demo trying to get it up and running within a mono repo. I'm specifically losing type inference for the api.users.get that return the lucia auth object.

I just tested a query that was from a previous project, and wrapped with the helpers from the auth demo, in this case:


This works:
// Query
export const all = queryWithAuth({
  args: { amount: v.number() },
  handler: async (ctx, args) => {
    const videos = await ctx.db.query('videos').order('desc').take(args.amount)

    return await Promise.all(
      videos.map(async (video) => await enrichWithExtras(ctx, video))
    )
  },
})

// example
import { api } from 'backend/convex/_generated/api'
import { useQuery } from '@/lib/usingSession'

const SomeComponent = () => {
  const videos = useQuery(api.queries.videos.all, { amount: 80 }) // This returns videos with it's inferred type
  // ... rest of component
}


This wont work:
// Query
import { v } from 'convex/values'

import { Id } from './_generated/dataModel'
import { queryWithAuth, mutationWithAuth } from '../helpers/withAuth'

export const get = queryWithAuth({
  args: {},
  handler: async (ctx) => {
    return ctx.session?.user
  },
})

// Example
import { api } from 'backend/convex/_generated/api'
import { useQuery } from '@/lib/usingSession'

const SomeComponent = () => {
   const user = useQuery(api.users.get, {}) // does not return user object
  // ... rest of component
}
Was this page helpful?