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.
Environment
.envYOURSELF_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/callbackAdd the helper
One file, one dependency (
jose). It does PKCE, state and nonce checks, ID token verification, and a signed session cookie.shnpm install jose curl -fsSL https://yourself.mees.sh/sdk/yourself-auth.ts -o src/lib/server/yourself-auth.tsConfigure it
src/lib/server/auth.tsimport { 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!, });Routes
src/routes/auth/[action]/+server.tsimport { 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); };Guard every page
src/hooks.server.tsimport { 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); };Type the local
src/app.d.tsimport type { YourselfUser } from "$lib/server/yourself-auth"; declare global { namespace App { interface Locals { user: YourselfUser; } } } export {};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.