Skip to main content

auth_guard

Function auth_guard 

Source
pub async fn auth_guard(
    __arg0: State<State>,
    request: Request,
    next: Next,
) -> Result<Response>
Expand description

Middleware that guards protected routes by validating the session token.

Extracts the Bearer token from the Authorization header, computes its hash, and checks the in-memory cache. If missing from the cache, it verifies the token against the database and caches the result for future requests.

ยงErrors

  • Returns an Unauthorized if the Authorization header is missing, malformed, or contains an invalid/expired token.
  • Returns a BadRequest if the token string cannot be serialized.
  • Returns an internal error if a database query fails.