Eldersonar
CCConvex Community
•Created by Eldersonar on 2/22/2025 in #support-community
Getting all organization users by org id from clerk
is this a version incompatibility issue?
21 replies
CCConvex Community
•Created by Eldersonar on 2/22/2025 in #support-community
Getting all organization users by org id from clerk
using "@clerk/nextjs": "^5.7.5"
21 replies
CCConvex Community
•Created by Eldersonar on 2/22/2025 in #support-community
Getting all organization users by org id from clerk
@Tom thoughts?
21 replies
CCConvex Community
•Created by Eldersonar on 2/22/2025 in #support-community
Getting all organization users by org id from clerk
ok, so I came up with a script that utilizes the clerk sdk and fetches users by org, however, Convex is giving me hard time.
path - convex/users.ts
import { query } from "./_generated/server";
import { v } from "convex/values";
import { clerkClient } from "@clerk/nextjs/server";
import type { OrganizationMembership, User } from "@clerk/nextjs/server";
export const getOrganizationMembers = query({
args: {
organizationId: v.string(),
},
handler: async (ctx, { organizationId }) => {
try {
// Get organization memberships
const membershipsResponse = await clerkClient.organizations.getOrganizationMembershipList({
organizationId
});
// Extract user IDs const userIds = membershipsResponse.data .map((m: OrganizationMembership) => m.publicUserData?.userId) .filter((id): id is string => id !== undefined);
if (userIds.length === 0) { return []; } // Get user details const users = await clerkClient.users.getUserList({ userId: userIds });
return users.data as User[]; } catch (error) { console.error("Failed to fetch organization members:", error); throw new Error("Failed to fetch organization members"); } } }); ⠇ Preparing Convex functions... X [ERROR] Could not resolve "node:async_hooks" node_modules/@clerk/nextjs/dist/esm/server/clerkMiddleware.js:1:34:
1 │ import { AsyncLocalStorage } from "node:async_hooks"; ╵~~~~~~
The package "node:async_hooks" wasn't found on the file system but is
built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error. I tried to get AI assistance and was told to add a convex.json file in the root of my directory and populate it with { "bundler": { "platform": "node" } } it didn't work. What am I doing wrong here?
// Extract user IDs const userIds = membershipsResponse.data .map((m: OrganizationMembership) => m.publicUserData?.userId) .filter((id): id is string => id !== undefined);
if (userIds.length === 0) { return []; } // Get user details const users = await clerkClient.users.getUserList({ userId: userIds });
return users.data as User[]; } catch (error) { console.error("Failed to fetch organization members:", error); throw new Error("Failed to fetch organization members"); } } }); ⠇ Preparing Convex functions... X [ERROR] Could not resolve "node:async_hooks" node_modules/@clerk/nextjs/dist/esm/server/clerkMiddleware.js:1:34:
1 │ import { AsyncLocalStorage } from "node:async_hooks"; ╵
built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error. I tried to get AI assistance and was told to add a convex.json file in the root of my directory and populate it with { "bundler": { "platform": "node" } } it didn't work. What am I doing wrong here?
21 replies
CCConvex Community
•Created by Eldersonar on 2/22/2025 in #support-community
Getting all organization users by org id from clerk
looking
21 replies
CCConvex Community
•Created by Eldersonar on 2/22/2025 in #support-community
Getting all organization users by org id from clerk
this is my initial attempt
21 replies
CCConvex Community
•Created by Eldersonar on 2/22/2025 in #support-community
Getting all organization users by org id from clerk
I have not
21 replies
CCConvex Community
•Created by Eldersonar on 2/22/2025 in #support-community
Getting all organization users by org id from clerk
Perhaps I could set up webhooks of Clerk and listen to them on my app, then make updates to the users table in convex, but I was wondering if there is an easier, more streamlined way to directly query clerk
21 replies