use axum::{
    extract::Request,
    middleware::Next,
    response::{IntoResponse, Response},
};

use infra::{status::api_err::ApiErr, util::iden::Identity};

pub async fn auth_mw(req: Request, next: Next) -> Response {
    let unauthorized = {
        match req.extensions().get::<Identity>() {
            None => true,
            Some(v) => v.id() == 0,
        }
    };
    if unauthorized {
        return ApiErr::Unauthorized.into_response();
    }

    // TODO: ...

    next.run(req).await
}
