amppA
Convex Community2y ago
3 replies
ampp

Pagination with authQuery

Should i just pass my userid in the lame way through args? I want to do it the best way.

export const getMyTickets2 = authQuery({
args: { paginationOpts: paginationOptsValidator },
handler: async (ctx, args) => {

if (!ctx.user) throw new Error("User not found");

return await ctx.db
.query("ticket")
.filter((q) => q.eq(q.field("userId"), ctx.user._id))
.paginate(args.paginationOpts);
},
});

Because if i refresh the page with this pagination the user is not found.

This also doesnt work

export const getMyTickets = query({
args: { paginationOpts: paginationOptsValidator },
handler: async (ctx, args) => {
const { db, auth } = ctx

const user = await findUser(db, auth);
if (!user?._id) {
throw new Error('Error: User identity not found')
}

return await ctx.db
.query("ticket")
.withIndex('by_userId', (q) => q.eq('userId', user._id))
.order("asc")
.paginate(args.paginationOpts);
},
});
Was this page helpful?