SvelteKit

A server hook guards every route and puts the owner on `event.locals.user`.

Register the app first: ask your agent, or create a web app in the dashboard with redirect URI http://localhost:5173/auth/callback.

  1. Environment

    .env
    YOURSELF_ISSUER=https://yourself.mees.sh
    YOURSELF_CLIENT_ID=app_…
    YOURSELF_CLIENT_SECRET=ysec_… (shown once when the app was created; rotate it if lost)
    YOURSELF_REDIRECT_URI=http://localhost:5173/auth/callback
  2. Add the helper

    One file, one dependency (jose). It does PKCE, state and nonce checks, ID token verification, and a signed session cookie.

    sh
    npm install jose
    curl -fsSL https://yourself.mees.sh/sdk/yourself-auth.ts -o src/lib/server/yourself-auth.ts
  3. Configure it

    src/lib/server/auth.ts
    import { env } from "$env/dynamic/private";
    import { createYourselfAuth } from "./yourself-auth";
    
    export const auth = createYourselfAuth({
      issuer: env.YOURSELF_ISSUER!,
      clientId: env.YOURSELF_CLIENT_ID!,
      clientSecret: env.YOURSELF_CLIENT_SECRET!,
      redirectUri: env.YOURSELF_REDIRECT_URI!,
    });
  4. Routes

    src/routes/auth/[action]/+server.ts
    import { error } from "@sveltejs/kit";
    import { auth } from "$lib/server/auth";
    
    export const GET = ({ request, params }) => {
      if (params.action === "login") return auth.signIn(request);
      if (params.action === "callback") return auth.handleCallback(request);
      error(404);
    };
    
    export const POST = ({ params }) => {
      if (params.action === "logout") return auth.signOut();
      error(404);
    };
  5. Guard every page

    src/hooks.server.ts
    import { redirect, type Handle } from "@sveltejs/kit";
    import { auth } from "$lib/server/auth";
    
    export const handle: Handle = async ({ event, resolve }) => {
      if (event.url.pathname.startsWith("/auth/")) return resolve(event);
      const user = await auth.getUser(event.request);
      if (!user) redirect(303, `/auth/login?return_to=${encodeURIComponent(event.url.pathname + event.url.search)}`);
      event.locals.user = user;
      return resolve(event);
    };
  6. Type the local

    src/app.d.ts
    import type { YourselfUser } from "$lib/server/yourself-auth";
    
    declare global {
      namespace App {
        interface Locals {
          user: YourselfUser;
        }
      }
    }
    
    export {};
  7. 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.