Skip to content

AuthContextOptions

U extends AuthUser = AuthUser

A = unknown

readonly auth: TrpcAuth<U, A>

The createAuth(...) result.


readonly optional clientIpHeader?: string

A single-address header your edge sets, such as cf-connecting-ip. Needs trustedHops as a list naming the edge (or hops that accept traffic only from it); read only when the socket address is inside that list and the value is exactly one IP, otherwise X-Forwarded-For decides. Off by default.


readonly csrf: CsrfOptions


readonly optional revalidateSubscriptions?: false | Duration

How long a subscription behind a session check (authed, freshAuth, role, protectedProcedure, the nestjs-trpc guard) may go on sending events on the session it opened with. tRPC builds the context once per HTTP request, and an SSE subscription is one request that stays open, so its session is validated once. Before an event leaves, when the last check is older than this, the session is validated again (without counting as activity) and its user loaded; when either is gone, or the session became enrollment-only, the stream ends with session_expired (or two_factor_enrollment_required) instead of the event. 0 checks before every event. false turns it off. Default 30s.


readonly optional roles?: (user) => readonly string[] | Promise<readonly string[]>

The user’s roles, for role(...). Called on every call that needs a role, with the user just loaded from the store, so a role change takes effect on the next request.

U

readonly string[] | Promise<readonly string[]>


readonly optional touch?: boolean | ((path) => boolean)

Whether a request counts as activity for the session’s idle timeout. true (the default) refreshes the session’s last-active time, at most once per touchInterval, on every request. A predicate is asked about each procedure path of the request (notifications.count), before the session is validated: return false for procedures the page calls on its own (a poll on a timer, a status check), so an idle session still expires while only they are called. A procedure whose meta says touch: false is passive too. A batch touches when any of its procedures is active. false touches on no request. A passive request is still answered with its session, and the CSRF verdict and the guarded procedures’ decisions do not change.


readonly trustedHops: TrustedHops

How many reverse proxies sit in front of the server, counted from the right of X-Forwarded-For (the core’s clientIp rule), 0 when none; or a list of proxy addresses, CIDR ranges and the presets loopback, linklocal and uniquelocal, trusted by the socket address.