Overview
ThegetClerkUsers function retrieves user information from Clerk based on an array of user IDs (email addresses). It requires authentication and returns formatted user objects with id, name, email, and avatar.
Function Signature
Parameters
Array of email addresses to fetch user details for. The returned users will be sorted in the same order as the input array.
Return Value
Array of user objects sorted in the same order as the input
userIds. Returns undefined if an error occurs.Code Example
Error Handling
The function handles errors gracefully and logs them to the console. It returnsundefined when:
- The current user is not authenticated (no email found)
- The Clerk API request fails
- Any other error occurs during execution
Authentication
The function automatically checks if the current user is authenticated by retrieving their email. If no authenticated user is found, it throws an “Unauthorized to list users” error.
Implementation Details
- Uses
clerkClient.users.getUserList()to fetch user data - Transforms Clerk user objects into a simplified format
- Preserves the order of input
userIdsin the returned array - Uses
parseStringifyutility for serialization
Related
- getDocumentUsers - Fetch users with access to a specific document