oscklm
oscklm15mo ago

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
}
// 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
}
// 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
}
3 Replies
oscklm
oscklmOP15mo ago
I might just lack knowledge here. But i've tried all day to get it working, and have tried several ways of back tracking trying to figure out where it goes wrong. I've delved deep into the query wrappers, and how they are setup - but i fail to see exactly where the type inference is lost here. I would love if anyone could point me in the right direction. The project is quite large, but let me know if more context is needed here or any specific files from my project.
Michal Srb
Michal Srb15mo ago
hey @oscklm, can you try with https://github.com/get-convex/convex-lucia-auth (docs: https://github.com/get-convex/convex-lucia-auth/blob/master/DOCS.md) The type inference is definitely quite finicky, and can be broken easily (for example if there's any error, or if any of the definition files is missing). For either of them you need the env.d.ts file set up correctly.
GitHub
GitHub - get-convex/convex-lucia-auth: Convex database adapter for ...
Convex database adapter for Lucia Auth. Contribute to get-convex/convex-lucia-auth development by creating an account on GitHub.
oscklm
oscklmOP15mo ago
Thanks Michael. I’ll take a look, also when I have time I’d love to at least to a try with the current repo I have, and back track to see if I can get it working and learn why. But the project is rather large, so will take a bit of time i think. I’ll update this if and when I learn more.

Did you find this page helpful?