Get started
Embedded Studio

Quickstart

Quickstart

Mount the Mountaya editor in a Vite and React app. You need the prerequisites: an agreement, a key with the studio-embedded scope, and your domain allowed.

1

Install the packages
npm install @mountaya/studio-react @mountaya/studio @mountaya/elements-react @mountaya/elements \
  @mountaya/client-react @mountaya/client @tanstack/react-query maplibre-gl@6.16.0 react react-dom

2

Mint the token on your server

The studio acts as one of your members. Add a route behind your own sign-in that mints a token for them.

// server/mountaya-session.ts
import { Mountaya } from "@mountaya/client";

const mountaya = new Mountaya({
  credential: { secretKey: process.env.MOUNTAYA_SECRET_KEY ?? "" },
});

// Answer GET /api/mountaya-session with this, behind your own sign-in.
// userId is the Mountaya member your session vouches for, never a request field.
export async function mintStudioSession(userId: string): Promise<Response> {
  const { data } = await mountaya.admin.sessions.postSession({
    body: {
      publishable_key: process.env.MOUNTAYA_PUBLISHABLE_KEY ?? "",
      surface: "studio-embedded",
      user_id: userId,
    },
  });

  return Response.json(data, { headers: { "Cache-Control": "no-store" } });
}
Response
{
  "expires_at": "2026-11-09T12:00:34.604201Z",
  "token": "sess_your_session_token",
  "user_id": "7a4e1c98-3b52-4f60-9d81-c05e2f7a83b1"
}

3

Mount the studio

Replace src/main.tsx. In development, proxy /api to your server with Vite's server.proxy.

// src/main.tsx
/// <reference types="vite/client" />
import "@mountaya/studio-react/styles.css";

import { Mountaya } from "@mountaya/client/browser";
import { useSessionToken } from "@mountaya/client-react";
import { MountayaStudio, MountayaStudioHost } from "@mountaya/studio-react";
import { StrictMode, useState } from "react";
import { createRoot } from "react-dom/client";

const publishableKey = import.meta.env.VITE_MOUNTAYA_PUBLISHABLE_KEY;

const mintSession = async () => {
  const response = await fetch("/api/mountaya-session");
  if (!response.ok) {
    throw new Error(`The session endpoint answered ${response.status}.`);
  }
  return response.json();
};

const Studio = () => {
  const { session } = useSessionToken({ mint: mintSession });
  const [client] = useState(
    () => new Mountaya({ credential: { publishableKey, sessionToken: session } }),
  );

  return (
    <MountayaStudioHost client={client}>
      <MountayaStudio />
    </MountayaStudioHost>
  );
};

const root = document.querySelector("#root");
if (root === null) {
  throw new Error("index.html has no #root element.");
}

createRoot(root).render(
  <StrictMode>
    <Studio />
  </StrictMode>,
);

Set VITE_MOUNTAYA_PUBLISHABLE_KEY in .env.local, run npm run dev, and the editor fills the page. Pass itineraryId to the host to open one itinerary.

Next steps

Last updated