Luke
CCConvex Community
•Created by Luke on 1/17/2024 in #support-community
Access Clerk Organization in Query
I am authenticating users in my app via Clerk and can easily query for Clerk userId when making requests via ctx.auth. However I want to link an entity in my DB to Clerk Organizations and I don't have that information readily available in the Convex environment/context.
Is there a recommended approach to this from within Convex? The way I am thinking now is either fetching via Clerk in the frontend and passing it to the query each time or duplicating all of the Clerk data in Convex, but I'm not too keen on that.
5 replies
CCConvex Community
•Created by Luke on 10/16/2023 in #support-community
Best practices for joining data in query
I am attempting to join a project's notes to this query, I get no errors however the type inference insists that the property does not exist when I try to access it in the response.
export const getProjectById = query({
args: { projectId: v.id("projects") },
handler: withUser(async ({ db, user }, { projectId }) => {
const project = await db.get(projectId);
if (!project) {
throw new Error("Project not found");
}
if (project.user !== user._id) {
throw new Error("Unauthorized");
}
const notes = await db
.query("notes")
.withIndex("by_project", (q) => q.eq("project", project._id))
.collect();
return {
...project,
notes: notes,
};
}),
});
46 replies