Build a 2D replay portal
Combine Public API v2 OIDC viewer sessions with @strave/replay-embed to build custom match review pages.
This guide builds a Next.js match recap page that frames Strave's 2D replay viewer and adds custom round buttons and speed controls around it.
1. Create a server route that mints a viewer session
Never expose Strave OIDC tokens to the browser. Mint a short-lived session
server-side and bind it to your site's exact https:// origin:
// app/api/replays/[matchId]/session/route.ts
import { createStraveClient } from "@strave/sdk";
import { getVercelOidcToken } from "@vercel/oidc";
const strave = createStraveClient({
oidcWorkload: {
clientId: process.env.STRAVE_CLIENT_ID!,
getAssertion: () =>
getVercelOidcToken({ audience: "https://strave.gg/api/auth" }),
scopes: ["event:read"],
},
});
export async function POST(
request: Request,
context: { params: Promise<{ matchId: string }> },
) {
const { matchId } = await context.params;
const { eventId, mapIndex = 0 } = await request.json();
const { data } = await strave.replays.createViewerSession(matchId, mapIndex, {
eventId,
origin: "https://tournaments.example.com",
ttlSeconds: 300,
});
return Response.json(data, { headers: { "cache-control": "no-store" } });
}2. Mount @strave/replay-embed/react with custom controls
"use client";
import {
StraveReplayEmbed,
type StraveReplayEmbedController,
} from "@strave/replay-embed/react";
import { useRef, useState } from "react";
export function ReplayPortal({ embedUrl }: { embedUrl: string }) {
const controllerRef = useRef<StraveReplayEmbedController | null>(null);
const [rounds, setRounds] = useState<readonly number[]>([]);
const [activeRound, setActiveRound] = useState(1);
return (
<div className="space-y-3">
<div className="flex flex-wrap gap-2">
{rounds.map((round) => (
<button
key={round}
type="button"
onClick={() => controllerRef.current?.setRound(round)}
className={round === activeRound ? "font-bold underline" : ""}
>
Round {round}
</button>
))}
<button
type="button"
onClick={() => controllerRef.current?.togglePlay()}
>
Play / Pause
</button>
</div>
<div className="aspect-video w-full overflow-hidden rounded-xl border">
<StraveReplayEmbed
embedUrl={embedUrl}
onController={(ctrl) => {
controllerRef.current = ctrl;
}}
onEvent={(event) => {
if (event.type === "ready") setRounds(event.rounds);
if (event.type === "roundChange") setActiveRound(event.round);
}}
/>
</div>
</div>
);
}