Skip to main content

require_auth_for

Function require_auth_for 

Source
pub async fn require_auth_for<U: Authenticatable>(
    session: Session,
    request: Request,
    next: Next,
) -> Response
Expand description

require_auth’s named-guard counterpart (Laravel’s Auth::guard('admin') protecting a route group) - redirects unless U::GUARD specifically is logged in, regardless of whether some other guard is. Used as require_auth_for::<Admin>, e.g. r.middleware(axum::middleware::from_fn(require_auth_for::<Admin>)).

Redirects to a route named "{guard}.login" (e.g. "admin.login" for Admin::GUARD == "admin") rather than the plain "login" require_auth uses - a named second guard almost always has its own, separate login page. Falls back to plain "login", then to a hardcoded /login, with a warning at each step, if the more specific name isn’t registered - the same degrade pattern require_auth already uses.