Grant access to individual rooms with access tokens
With access tokens we always recommend using a naming pattern to grant access to multiple rooms at once, for example every room in a user’s organization.
However, it may not always be possible to grant access to every room with a wildcard and naming pattern. One example would be if a user is invited to only one room in a different organization. There’s a way to work around this limitation.
Grant access to individual rooms
When using
authEndpoint
,
Liveblocks provides the current room ID in the request
. Below is a Next.js
example, where the current room ID is taken from the body, and the user is
allowed access to the room. Note that room
is undefined
when
Notifications is authenticating, which
is why we’re checking if it exists. Notifications works across rooms, and it
doesn’t require any permissions.
This approach relies on you creating the __shouldUserHaveAccess__
function,
and determining whether the user is allowed inside the room.