React Router v7 / Remix (framework mode)

Resource routes for sign-in and a loader check in the root layout.

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 app/yourself-auth.server.ts
  3. Configure it

    app/auth.server.ts
    import { redirect } from "react-router";
    import { createYourselfAuth } from "./yourself-auth.server";
    
    export const auth = createYourselfAuth({
      issuer: process.env.YOURSELF_ISSUER!,
      clientId: process.env.YOURSELF_CLIENT_ID!,
      clientSecret: process.env.YOURSELF_CLIENT_SECRET!,
      redirectUri: process.env.YOURSELF_REDIRECT_URI!,
    });
    
    export async function requireUser(request: Request) {
      const user = await auth.getUser(request);
      if (!user) {
        const url = new URL(request.url);
        throw redirect(`/auth/login?return_to=${encodeURIComponent(url.pathname + url.search)}`);
      }
      return user;
    }
  4. Routes

    Register them in app/routes.ts: route("auth/:action", "routes/auth.ts").

    app/routes/auth.ts
    import { auth } from "../auth.server";
    import type { Route } from "./+types/auth";
    
    export function loader({ request, params }: Route.LoaderArgs) {
      if (params.action === "login") return auth.signIn(request);
      if (params.action === "callback") return auth.handleCallback(request);
      throw new Response("Not found", { status: 404 });
    }
    
    export function action({ params }: Route.ActionArgs) {
      if (params.action === "logout") return auth.signOut();
      throw new Response("Not found", { status: 404 });
    }
  5. Protect pages

    Call requireUser in the loader of any route (or a layout route that wraps them all).

    ts
    export async function loader({ request }: Route.LoaderArgs) {
      const user = await requireUser(request);
      return { user };
    }
  6. 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.