Skip to main content

user_context_layer

Function user_context_layer 

Source
pub async fn user_context_layer(req: Request, next: Next) -> Response
Expand description

Install a per-request lazy resolver on the [umbral::templates::CURRENT_USER_LAZY] channel.

The resolver clones the request headers and runs at most once, only when a template actually accesses {{ user }}. Requests that never render a template (JSON/API responses) pay zero DB reads. When the resolver does run it performs the session + user lookup and memoizes the result for the rest of the request.

Opt in via crate::AuthPlugin::with_user_in_templates when the app is HTML-heavy; leave off for REST-only services.