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);
},
});
3 Replies
if your query is no longer authenticated after a refresh, you should put the useQuery in a component that is wrapped in a
<Authenticated>
component, described here: https://docs.convex.dev/auth/clerkConvex Clerk | Convex Developer Hub
Clerk is an authentication platform providing login via
Isn't having the entire Root layout wrapped in a ConvexProviderWithClerk sufficient. I have not noticed this happening anywhere else.
ConvexProviderWithClerk
makes auth available, but the user doesn't have to be signed in. Authenticated
enforces that the user is actually signed in.
See https://docs.convex.dev/auth/clerk#logged-in-and-logged-out-viewsConvex Clerk | Convex Developer Hub
Clerk is an authentication platform providing login via