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.

  1. Environment

    SPAs have no client secret. These values are public.

    .env
    VITE_YOURSELF_ISSUER=https://yourself.mees.sh
    VITE_YOURSELF_CLIENT_ID=app_…
  2. Add the helper

    sh
    npm install jose
    curl -fsSL https://yourself.mees.sh/sdk/yourself-spa.ts -o src/yourself-spa.ts
  3. Gate the app on sign-in

    Your host must serve index.html for /callback (Vite's dev server and most static hosts do).

    src/main.tsx
    import { 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();
  4. Protect your API (optional)

    Send auth.getAccessToken() as a Bearer token. Your API verifies it against the issuer's keys; aud is the app's client ID.

    ts
    import { 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;
    }
  5. 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_activity MCP tool (or the dashboard) shows an app.signed_in event.