(frontend) allow unauthenticated participants to mute via LiveKit token

Pass the LiveKit token when calling the mute-participant endpoint
to authenticate the request.

This enables non-authenticated participants to mute others through
the API while preserving proper authorization checks.
This commit is contained in:
lebaudantoine
2026-03-24 19:07:55 +01:00
committed by aleb_the_flash
parent 288562cc0e
commit 388b7d172d
@@ -6,14 +6,15 @@ import {
NotificationType,
} from '@/features/notifications'
import { fetchApi } from '@/api/fetchApi'
import { useIsAdminOrOwner } from '../livekit/hooks/useIsAdminOrOwner'
export const useMuteParticipant = () => {
const data = useRoomData()
const apiRoomData = useRoomData()
const { notifyParticipants } = useNotifyParticipants()
const isAdminOrOwner = useIsAdminOrOwner()
const muteParticipant = async (participant: Participant) => {
if (!data?.id) {
if (!apiRoomData?.livekit?.room) {
throw new Error('Room id is not available')
}
const trackSid = participant.getTrackPublication(
@@ -24,25 +25,41 @@ export const useMuteParticipant = () => {
return
}
const headers = !isAdminOrOwner
? {
Authorization: `Bearer ${apiRoomData?.livekit?.token}`,
}
: undefined
try {
const response = await fetchApi(`rooms/${data.id}/mute-participant/`, {
method: 'POST',
body: JSON.stringify({
participant_identity: participant.identity,
track_sid: trackSid,
}),
})
await notifyParticipants({
type: NotificationType.ParticipantMuted,
destinationIdentities: [participant.identity],
})
const response = fetchApi(
`rooms/${apiRoomData?.livekit?.room}/mute-participant/`,
{
method: 'POST',
headers,
body: JSON.stringify({
participant_identity: participant.identity,
track_sid: trackSid,
}),
}
)
return response
} catch (error) {
console.error(
`Failed to mute participant ${participant.identity}: ${error instanceof Error ? error.message : 'Unknown error'}`
)
return
}
try {
await notifyParticipants({
type: NotificationType.ParticipantMuted,
destinationIdentities: [participant.identity],
})
} catch (e) {
console.error(
`Failed to notify muted participant ${participant.identity}: ${e}`
)
}
}
return { muteParticipant }