Skip to content

Application panics on find_user #735

@zleyyij

Description

@zleyyij

Ported from the discord: https://discord.com/channels/749314018837135390/1240828670986162247/1497274232818892860

I was going through some routine dep updates (hooray for vite 8 and typescript 6) and went to verify the frontend was still working.

From the user side everything still works fine, but I was seeing this error pop up

The application panicked (crashed).
Message:  called `Option::unwrap()` on a `None` value
Location: src/handlers_prelude/mod.rs:96

The function in question:

/// Find the user attached to a particular request, if there is one, and the access token is still valid
async fn find_user(state: &AppState, headers: HeaderMap) -> color_eyre::Result<Option<FoundUser>> {
    let mut cookies: HashMap<&str, &str> = HashMap::new();
    // There can be multiple cookie headers, and each cookie header can contain multiple cookies
    let cookie_headers = headers.get_all("Cookie");
    for cookie_header in cookie_headers {
        let deserialized_cookie = cookie_header
            .to_str()
            .wrap_err("Cookie header contains invalid UTF-8")?;
        for nv_pair in deserialized_cookie.split("; ") {
            let (name, value) = nv_pair.split_once('=').wrap_err("Malformed cookie")?;
            cookies.insert(name, value);
        }
    }

    let mut located_user: Option<FoundUser> = None;
    let token = cookies.get("access-token").unwrap();
    if let Some(user) = state.db.get_user_from_token(token.to_string()).await? {
      // ---- SNIP ----
    }

    Ok(located_user)
}

Replication

If you don't already have one, delete the access-token cookie from the browser, then start hyde up and login.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendRustbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions