Skip to main content

check_auth

Function check_auth 

Source
pub async fn check_auth(
    auth: &Option<Arc<AuthState>>,
    headers: &HeaderMap,
) -> Result<Option<String>, StatusCode>
Expand description

Check authentication for a protected endpoint.

Returns Ok(None) if auth is not configured (open mode), or if a valid token is present without needing cookie renewal. Returns Ok(Some(cookie)) if auth succeeded and the caller should include the given Set-Cookie header value in the response (rolling session). Returns Err(StatusCode) if auth is configured but no valid token is found.

Token sources (in order):

  1. Authorization: Bearer <token> header (raw JWT — validated directly)
  2. trustee_token=<session_id> cookie (looked up in WebSessionManager, auto-refreshed if near expiry)

Dev mode tokens use the format dev:email:name:username.