Skip to main content
1

Install

@trylath/sdk is the server half — it holds your secret key and calls operations. @trylath/react is the browser half and never sees a secret key.Two packages because they have opposite security properties, and one package that did both would make it easy to import the wrong one into a client component.
2

Send from the server

A route handler or a server action is where the secret key lives. Keep it in LATH_API_KEY and never in anything prefixed NEXT_PUBLIC_ — that prefix is what decides whether a value is compiled into the client bundle.
3

Sign-in, in the browser

LathProvider takes the publishable key and the environment id. SignIn renders the whole flow; SignedIn and SignedOut switch on the session; UserButton is the account menu.These are safe in a client component by construction — a publishable key can only call the operations marked auth:public.
4

Protect a route handler

requireUser verifies the caller’s access token against your environment’s published keys. It does not call Lath on every request — the signature is checked locally against a JWKS, so an authenticated route costs no round trip.It throws when the token is missing or invalid, so the happy path below is the only path you write.
5

Receive webhooks

A route handler must read the raw body — await req.text(), not await req.json() — because the signature is over the exact bytes that were sent. See the webhooks guide for why re-serialising breaks it.
Last modified on September 13, 2026