When a comment is posted, Liveblocks doesn’t store any user metadata, for example their avatar or name. Instead, it only saves their user ID, which you manually set when authenticating. To fetch user metadata, we provide functions that allow you to return the correct data.
You can set a user’s ID when authenticating your application, for example with
liveblocks.prepareSession
.
This ID is then used inside Comments to represent the current user, for example
we’re using an email address as a user ID below.
There are two different authentication methods—make sure to follow an authentication guide for your framework to get started.
In Comments, user information is retrieved from a list of user IDs, for example
here’s a userIds
array and the information you need to return. You should
return the same number of users as the number of user IDs, in the same order.
In your Liveblocks config file, you’ll find a function named
resolveUsers
where you
can return this information.
The name
, and avatar
are required for the default components, but you can
also return custom metadata here. For example, each user may have a color
property. You can retrieve these properties in your app with
useUser
.
Comments allows you to search for a user after typing the "@"
character.
When a user types "@"
and searches for a user, Comments will pass you a text
property which you can use to return matching user IDs.
You can resolve these search results by editing a function named
resolveMentionSuggestions
in your Liveblocks config file. Here’s what the function might look like if the
user has typed "@mar"
into the input.
If a user has only typed "@"
, text
is an empty string, and it’s recommended
to return every user.
We use cookies to collect data to improve your experience on our site. Read our Privacy Policy to learn more.