React / Vite single-page app
A public client with PKCE: no secret, tokens kept in sessionStorage.
Register the app first: ask your agent, or create a spa app in the dashboard with redirect URI http://localhost:5173/callback.
Environment
SPAs have no client secret. These values are public.
.envVITE_YOURSELF_ISSUER=https://yourself.mees.sh VITE_YOURSELF_CLIENT_ID=app_…Add the helper
shnpm install jose curl -fsSL https://yourself.mees.sh/sdk/yourself-spa.ts -o src/yourself-spa.tsGate the app on sign-in
Your host must serve
index.htmlfor/callback(Vite's dev server and most static hosts do).src/main.tsximport { createRoot } from "react-dom/client"; import App from "./App"; import { createYourselfSpa } from "./yourself-spa"; export const auth = createYourselfSpa({ issuer: import.meta.env.VITE_YOURSELF_ISSUER, clientId: import.meta.env.VITE_YOURSELF_CLIENT_ID, redirectUri: `${location.origin}/callback`, }); async function start() { if (location.pathname === "/callback") { const { returnTo } = await auth.handleCallback(); history.replaceState(null, "", returnTo); } const user = auth.getUser(); if (!user) return auth.signIn(); createRoot(document.getElementById("root")!).render(<App user={user} />); } start();Protect your API (optional)
Send
auth.getAccessToken()as a Bearer token. Your API verifies it against the issuer's keys;audis the app's client ID.tsimport { createRemoteJWKSet, jwtVerify } from "jose"; const ISSUER = "https://yourself.mees.sh"; const jwks = createRemoteJWKSet(new URL(`${ISSUER}/.well-known/jwks.json`)); export async function requireOwner(request: Request) { const token = request.headers.get("authorization")?.replace(/^Bearer /, "") ?? ""; const { payload } = await jwtVerify(token, jwks, { issuer: ISSUER, audience: "app_…", typ: "at+jwt" }); return payload.sub; }Check it works
Start the app and open it. You're sent to yourself, sign in with your passkey, and land back in the app signed in. The
list_activityMCP tool (or the dashboard) shows anapp.signed_inevent.