Skip to main content

require_auth

Function require_auth 

Source
pub async fn require_auth(
    session: Session,
    request: Request,
    next: Next,
) -> Response
Expand description

Redirects a guest to "login" (falling back to a hardcoded /login, with a warning, if that route name isn’t registered - the same degrade pattern larust_support::redirect()->route() already uses) rather than running the handler. Pair with routes that require a logged-in user (Laravel’s auth middleware); use the crate::Auth extractor instead on routes that should fail with a 401 rather than redirect.

Checks the default ("web") guard; for a named second guard, use require_auth_for instead.