TheAuthModule.forRoot(options) is a NestJS dynamic module that mounts all theAuth routes as Express middleware. Import it once in your root AppModule.
Install
Setup
1
Create the theauth instance
2
Import TheAuthModule
3
Bootstrap
NestJS uses Express under the hood by default. The adapter mounts an Express Router directly, so no extra configuration is needed.
Route prefix
The default mount path is/api/theauth. Change it with the basePath option:
/auth/*.
Without a module
If you prefer to mount routes imperatively inmain.ts rather than importing a module, use theAuthMiddleware directly:
MCP endpoints
Passmcp to enable the MCP OAuth 2.1 authorization server:
Management routes and client IP
With the default session guard, a signed-in user only acts on their own agents, delegations and audit rows. A customauthenticate resolver is a trust decision and sees everything.
The adapter does not read forwarded headers for the client IP. Behind a proxy, set trustedProxy with trustedProxyCount or trustedHeader, or ipAllowlist constraints cannot match.
trustedHeader: 'cf-connecting-ip'. Only trust a header your edge overwrites.
Endpoint reference
Every adapter serves the same routes with the same status codes. See the route reference.Protect a route for agents
{ "error": { "code", "message" } }, where code is the decision code (for example no_permission). See the requireScope guide.
Related
Adapters overview
Compare all available framework adapters and their mount patterns.
Express
Router-based adapter for Express apps (NestJS uses Express internally).
Fastify
Plugin-based adapter if you use NestJS with the Fastify platform.
MCP
OAuth 2.1 authorization server endpoints mounted by the adapter.