Auth / foldkit-auth
One host: AuthServer.host
A server answering Yielded's auth routes, /remote, and SSR page reads needs
three configurations over one Auth service. AuthServer.host builds all three
from one config and types scripted and navigation separately so they cannot
be swapped by mistake:
ts
const host = AuthServer.host({
auth: AppAuth,
http,
services, // AppAuth's layer, built once: ManagedRuntime.make(AppAuthLive).context()
principal,
key: Policy.key,
})
export const site = {
auth: host.routes, // Yielded's routes under /auth/
remote: serveFetch({ server, layer: () => Layer.empty, ...host.scripted }),
read: pageReader({ server, layer: () => Layer.empty, ...host.navigation }),
}host.scriptedrequires a trustedOriginandx-effect-auth-csrf: 1and attachesAuthServer.answeredheaders whenkeyis set. Typed asScriptedRequest, so passing it topageReaderis a compile error.host.navigationallowsGET/HEADnavigations and refuses writes, upgrades, and scriptfetches. Typed asNavigationRequest, so passing it toserveFetchordefineDocumentHostis a compile error.servicesprovidesAuthautomatically inside bothhost.scriptedandhost.navigation; eachlayercallback only supplies what your Sources andprincipalneed. Buildservicesonce per isolate (never per request).- Routes:
host.routesmountsHttp.make(auth, http)(without OAuth callbacks; passinghttp.oauththrows). Sync sockets still takeAuthServer.resolver({ requests: 'browser', … }). Callhost.dispose()when shutting down;servicesstays caller-managed.
See examples/reference/src/worker.ts
on Workers and examples/auth/src/server.ts
on Node.