hocino
CCConvex Community
•Created by hocino on 12/11/2024 in #support-community
Understand how Context works in test environment with Identity
Hi Everyone,
I'm a bit confused about the context in my test. Here's what I'm trying to achieve:
I want to check if a user can access a document created by another user. To do this:
1 - I created an identity (asViewer) for the user (viewer) who wants to access the document.
2 - Then, I verified that the owner of the document can retrieve this user by using t.run. This part works fine.
3 - Next, I called my mutation, which is responsible for adding permissions to the document for the viewer. I executed this mutation with the asOwner identity, but it throws an error. The mutation is unable to retrieve the viewer user.
Here is the relevant part of my code:
const { asUser: asViewer, user: viewer } = await createIdentity(t);
const getViewerAsOwner = await asOwner.run(async (ctx) => {
return await ctx.db.get(viewer._id);
});
asOwner.mutation(api.core.permissions.insert, {
subjectId: viewer._id,
entityId: ownedApplication._id,
entityType: 'applications',
role: 'viewer',
});
I don't understand why I'm able to retrieve the viewer user when I execute asOwner.run, but not when I execute asOwner.mutation. Did I miss something? Could someone explain this behavior to me?
Thank you34 replies
CCConvex Community
•Created by hocino on 12/10/2024 in #support-community
CustomFunctions, vitest and multiple query call in a query
Hi everyone,
I'm struggling on a test. Vitest throw an error as below :
❯ Module.checkIfAuthorizedToCreateObject convex/validator.ts:9:15
7| ctx: GenericMutationCtx<DataModel>
8| ) => {
9| const sub = await ctx.runQuery(api.subscriptions.getSubscriptionInformation)
| ^
{
stack: 'Error: \n' +
' at performAsyncSyscall \n' +
' at runUdf \n' +
It's a query which is called inside a query (customQuery). I don't understand why, there are some limitations with vitest when we use custom functions or when we call queries in a query ?
thank you9 replies
CCConvex Community
•Created by hocino on 12/9/2024 in #support-community
custom functions and getAll helper
Hi everyone🙂 ,
I create two custom functions to handle my queries and mutations.
Now, when I use the getAll helper as below I have some strange errors. Except that I can query or mutate everything with my customFunctions.
Do you have any idea what is the problem ? Did I do something wrong with my custom Functions ?
Thanks 🙏
GetAll :
applicationsToUpdate = await getAll(
ctx.db,
childrenApplicationsIds.map((x) => x as Id<'applications'>)
);
Here, thrown errors :
Uncaught TypeError: Cannot read properties of undefined (reading 'reader')
or
Uncaught TypeError: Cannot read properties of undefined (reading 'db')
My customs functions:
export const SecureMutationBuilder = customMutation(mutation, {
args: {},
input: async (ctx, args) => {
const { userId, userPermissions } = await getPermissions(ctx);
const db = wrapDatabaseWriter(
{ userId },
ctx.db,
await rlsRules(ctx, userId, userPermissions)
);
return { ctx: { db, userId, userPermissions }, args };
}
});
export const SecureInternalMutationBuilder = customMutation(internalMutation, {
args: {},
input: async (ctx, args) => {
const { userId, userPermissions } = await getPermissions(ctx);
const db = wrapDatabaseWriter(
{ userId },
ctx.db,
await rlsRules(ctx, userId, userPermissions)
);
return { ctx: { db, userId, userPermissions }, args };
}
});
13 replies
CCConvex Community
•Created by hocino on 10/11/2024 in #support-community
Re execute query with React when parameter change
Hi everyone,
I use useQuery with react to execute my query but one query's parameter depends from a select tag, How can I reexecute my query when the selected value change. I'm pretty sure I saw something to do that on discord or stack.convex, I didn't retrieve it.
Thank for your help
7 replies