Authentication in the SDK
The publishable key goes in every client. A session token goes beside it for the Data API, for drafts, and for every write. Your server mints the token with the secret key, and the client keeps it fresh.
Add one route that calls postSession with your secret key:
That is a Next.js route handler. Authentication has the same route for Express and FastAPI.
Give the client a SessionTokenEngine. It calls your route, and mints again before each token expires:
One client serves the whole page. Each request, and each map tile, carries the current token.
useSessionToken holds the engine for you. Build the client once over its session:
Mount it inside your QueryClientProvider. Pass enabled: false while nobody is signed in.
A token minted without user_id reads only what your organization publishes, and writes nothing. To read drafts and write, mint the token for the member your own sign-in vouches for:
Read userId from your server's session, never from the request. Every call made with the token acts as that member.
The Embedded Studio takes only tokens minted for it. Add surface: "studio-embedded" to the mint:
The studio quickstart wires it end to end.
In every bundle that reaches a browser, import the client from @mountaya/client/browser. It has no secret-key credential, so passing one is a type error.