summaryrefslogtreecommitdiff
path: root/src/ui/middleware.rs
blob: f60ee1c51a7d7bbfd5e81858c8feaa5ff8150e5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use axum::{
    extract::{Request, State},
    middleware::Next,
    response::{IntoResponse, Redirect, Response},
};

use crate::{app::App, error::Internal};

pub async fn setup_required(State(app): State<App>, request: Request, next: Next) -> Response {
    match app.setup().completed().await {
        Ok(true) => next.run(request).await,
        Ok(false) => Redirect::to("/setup").into_response(),
        Err(error) => Internal::from(error).into_response(),
    }
}