How to stream signed Mux HLS video from Sanity CMS in a Next.js app
A developer tutorial outlines the full read path for playing Mux videos stored in Sanity CMS within a Next.js application, an area rarely covered in existing documentation. The process involves fetching a Mux asset's playbackId from Sanity using a GROQ query, then generating a short-lived signed JWT server-side via a Next.js Route Handler to avoid exposing the signing secret to the browser. Mux requires RS256-signed tokens with specific audience values — 'v' for video and 't' for thumbnails — and using incorrect audience claims is cited as the most common cause of 401 errors. The client component initialises hls.js only when the browser lacks native HLS support, since Safari handles HLS natively while Chrome does not. The guide also addresses poster frame handling to avoid negatively impacting Largest Contentful Paint scores.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in