M Zeeshan
M Zeeshan
CCConvex Community
Created by M Zeeshan on 10/4/2024 in #support-community
Schedule function
hello there I need to execute a specific task every minute on creation (api.some_task.create), but only for a duration of 10 minutes. Could someone please guide me on how to schedule this function?
27 replies
CCConvex Community
Created by M Zeeshan on 9/25/2024 in #support-community
Disable useQuery hook
Hello, I'm experiencing an issue with the Convex useQuery hook. Is it possible to disable it entirely? For instance, I've tried:
const disabled= ///////

const results = useQuery(api.hire_requests.notifications, { disabled });
const disabled= ///////

const results = useQuery(api.hire_requests.notifications, { disabled });
Currently, I'm handling this by checking the 'disabled' argument and returning if it's true. However, I'm wondering if there's a native or more idiomatic way to achieve this in Convex?"
3 replies
CCConvex Community
Created by M Zeeshan on 9/17/2024 in #support-community
Cannot find module dataModel
error:
utils/convex.ts:11:27 - error TS2307: Cannot find module '@/convex/_generated/dataModel' or its corresponding type declarations.

11 import { DataModel } from '@/convex/_generated/dataModel';
utils/convex.ts:11:27 - error TS2307: Cannot find module '@/convex/_generated/dataModel' or its corresponding type declarations.

11 import { DataModel } from '@/convex/_generated/dataModel';
import { DataModel } from '@/convex/_generated/dataModel';
import { GenericQueryCtx } from 'convex/server';

const getUser = async (ctx: GenericQueryCtx<DataModel>) => {
const user = await ctx.auth.getUserIdentity();

if (!user)
throw customConvexError({
type: 'unauthenticated',
message: 'unauthenticaed request',
});

return user;
};

export const secureZodQuery = zCustomQuery(query, {
args: {},
input: async (ctx) => {
const user = await getUser(ctx);

return { ctx: { ...ctx, user }, args: {} };
},
});
import { DataModel } from '@/convex/_generated/dataModel';
import { GenericQueryCtx } from 'convex/server';

const getUser = async (ctx: GenericQueryCtx<DataModel>) => {
const user = await ctx.auth.getUserIdentity();

if (!user)
throw customConvexError({
type: 'unauthenticated',
message: 'unauthenticaed request',
});

return user;
};

export const secureZodQuery = zCustomQuery(query, {
args: {},
input: async (ctx) => {
const user = await getUser(ctx);

return { ctx: { ...ctx, user }, args: {} };
},
});
3 replies
CCConvex Community
Created by M Zeeshan on 9/17/2024 in #support-community
Authentication in paginated query
How do I implement user authentication checks in paginated queries error:
Type '{ success: boolean; message: string; }' is missing the following properties from type 'PaginationResult<any>': page, isDone, continueCursor
Type '{ success: boolean; message: string; }' is missing the following properties from type 'PaginationResult<any>': page, isDone, continueCursor
server:
query({
handler: async () => {
const user = await ctx.auth.getUserIdentity();

if (!user) {
return {
success: false,
message: 'unauthenticated request',
};
}

return await queryBuilder
.order('desc')
.paginate(args.paginationOpts);
},
});
query({
handler: async () => {
const user = await ctx.auth.getUserIdentity();

if (!user) {
return {
success: false,
message: 'unauthenticated request',
};
}

return await queryBuilder
.order('desc')
.paginate(args.paginationOpts);
},
});
front-end:
const { results, loadMore, status, isLoading } = usePaginatedQuery(
api.hire_requests.getMultiple, // <---- EROR HERE
args,
{ initialNumItems: 20 },
);
const { results, loadMore, status, isLoading } = usePaginatedQuery(
api.hire_requests.getMultiple, // <---- EROR HERE
args,
{ initialNumItems: 20 },
);
58 replies
CCConvex Community
Created by M Zeeshan on 9/16/2024 in #support-community
Clerk auth session in Convex functions
i know i can get user object like this by configuring auth.config.ts
const user = await ctx.auth.getUserIdentity();
const user = await ctx.auth.getUserIdentity();
and in httpActions
await fetch(url, {
headers: {
Authorization: `Bearer ${token}`,
},
});
await fetch(url, {
headers: {
Authorization: `Bearer ${token}`,
},
});
but how to get clerk active session in any function or httpAction ?
49 replies
CCConvex Community
Created by M Zeeshan on 9/15/2024 in #support-community
Retrieve Total Document Count Before Pagination
I want to retrieve the total number of documents found before pagination takes place. However, I tried the following code and encountered an error. error: Uncaught Error: A query can only be chained once and can't be chained after iteration begins. code:
let queryBuilder = ctx.db.query('skills');

if (title) {
// @ts-ignore
queryBuilder = queryBuilder.withSearchIndex('title', (q) =>
q.search('title', title),
);
}

queryBuilder = queryBuilder.filter((q) =>
q.eq(q.field('isDeleted'), false),
);

// some code //

if (type !== undefined) {
queryBuilder = queryBuilder.filter((q) =>
q.eq(q.field('type'), type),
);
}

const totalFound = await queryBuilder.collect();
const results = await queryBuilder.paginate(args.paginationOpts);
let queryBuilder = ctx.db.query('skills');

if (title) {
// @ts-ignore
queryBuilder = queryBuilder.withSearchIndex('title', (q) =>
q.search('title', title),
);
}

queryBuilder = queryBuilder.filter((q) =>
q.eq(q.field('isDeleted'), false),
);

// some code //

if (type !== undefined) {
queryBuilder = queryBuilder.filter((q) =>
q.eq(q.field('type'), type),
);
}

const totalFound = await queryBuilder.collect();
const results = await queryBuilder.paginate(args.paginationOpts);
77 replies
CCConvex Community
Created by M Zeeshan on 9/15/2024 in #support-community
Error in Server Component
hello there... I'm encountering an error in a server component and I'm unsure about the best approach to resolve it. Could you please provide guidance on how to handle this issue? error: Error: [Request ID: 04418ec216ae34ab] Server Error ArgumentValidationError: Value does not match validator. Path: .id Value: "j97chph1jdefahph6wf901rsfs70jy3d" Validator: v.id("skills")
const preloadedData = await fetchQuery(
api.skills.getSingle,
{ id },
);

if (!preloadedData.success) notFound()

return <>ui</>
const preloadedData = await fetchQuery(
api.skills.getSingle,
{ id },
);

if (!preloadedData.success) notFound()

return <>ui</>
12 replies
CCConvex Community
Created by M Zeeshan on 9/10/2024 in #support-community
How to apply filter before pagination?
In the provided code, why are filter calls applied first to paginate the documents, and then the Predicate function is applied to those paginated documents? What I need: I want to first search the database, and then apply pagination to the filtered results. How can I modify the code to achieve this? Provided Code:
const results = await filter(ctx.db.query('skills'), (doc) => {
return (
doc.is_deleted === false &&
(args.is_featured === undefined ||
doc.is_featured === args.is_featured) &&
(args.is_published === undefined ||
doc.is_published === args.is_published) &&
(!args.query || doc.title.includes(args.query))
);
}).paginate(args.paginationOpts);
const results = await filter(ctx.db.query('skills'), (doc) => {
return (
doc.is_deleted === false &&
(args.is_featured === undefined ||
doc.is_featured === args.is_featured) &&
(args.is_published === undefined ||
doc.is_published === args.is_published) &&
(!args.query || doc.title.includes(args.query))
);
}).paginate(args.paginationOpts);
21 replies
CCConvex Community
Created by M Zeeshan on 9/10/2024 in #support-community
Compound index
Hello everyone, I need some help with Convex database indexing. I have a table named 'skills' and I have two separate indexes on the is_published and is_featured fields. I need to query the data based on both these fields. Initially, I thought of using a compound index, but it seems like the withIndex method doesn't allow multiple .eq() checks. Is there any way to efficiently filter by both these fields using the indexes? Any help would be greatly appreciated!
3 replies
CCConvex Community
Created by M Zeeshan on 9/8/2024 in #support-community
Pagination with preloaded data
My main question is How to preload data with usePaginatedQuery
And i also want to ask... is this possible in Convex : Cursor-based pagination: allowing me to jump to a specific page using a cursor token Offset-based pagination...? current server code :
const result = await ctx.db
.query('skills')
.withSearchIndex('search_type', (q) =>
q.search('type', args.query!),
)
.paginate(args.paginationOpts);
const result = await ctx.db
.query('skills')
.withSearchIndex('search_type', (q) =>
q.search('type', args.query!),
)
.paginate(args.paginationOpts);
9 replies