Overview
ThegetDocumentUsers function retrieves a list of user email addresses that have access to a specific Liveblocks room (document). It supports optional text filtering and includes authorization checks.
Function Signature
Parameters
The Liveblocks room ID representing the document
Email address of the current authenticated user. Used for authorization verification.
Filter text to search for users. If empty string is provided, returns all users. The search is case-insensitive and matches email addresses containing the text.
Return Value
Array of email addresses for users with access to the room, excluding the current user. Returns
undefined if an error occurs.- If
textparameter is provided and has length > 0, returns filtered emails matching the search text - If
textis empty, returns all user emails with access to the room - Current user’s email is always excluded from results
Code Example
Fetch All Document Users
Filter Users by Text
Error Handling
The function handles errors gracefully and logs them to the console. It returnsundefined when:
- The current user is not authenticated
- The
currentUserparameter doesn’t match the authenticated user’s email - The Liveblocks room doesn’t exist or cannot be accessed
- Any other error occurs during execution
Authorization
The function performs two levels of authorization:
- Checks if a user is currently authenticated via Clerk
- Verifies that the authenticated user’s email matches the
currentUserparameter
Implementation Details
- Uses
liveblocks.getRoom()to fetch room data and access permissions - Extracts user emails from
room.usersAccessesobject keys - Excludes the current user from the results
- Performs case-insensitive filtering when
textis provided - Uses
parseStringifyutility for serialization
Use Cases
- Displaying a list of document collaborators
- Implementing user search/autocomplete in share dialogs
- Filtering collaborators by email pattern
- Managing document access permissions
Related
- getClerkUsers - Fetch detailed user information from Clerk