How to generate tokens for users to hide in their ...
# ask-ai
a
How to generate tokens for users to hide in their rooms
t
Thanks for reaching out, 徐旭. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To generate tokens for users that will be hidden in their rooms, you need to create a token with the
hidden
permission set to
true
in the video grant. Here’s how you can do it: Using LiveKit CLI:
Copy code
lk token create \
--api-key <key> \
--api-secret <secret> \
--identity <name> \
--room <room_name> \
--join \
--valid-for 1h \
--hidden
Programmatically using a server SDK (Node.js example):
Copy code
import { AccessToken, VideoGrant } from 'livekit-server-sdk';

const roomName = 'name-of-room';
const participantName = 'user-name';

const at = new AccessToken('api-key', 'secret-key', {
  identity: participantName,
});

const videoGrant: VideoGrant = {
  room: roomName,
  roomJoin: true,
  hidden: true
};

at.addGrant(videoGrant);

const token = await at.toJwt();
console.log('access token', token);
This will create a token that allows the user to join a room while being hidden from other participants. Sources: Authentication | LiveKit Docs