summaryrefslogtreecommitdiff
path: root/src/expire.rs
blob: 16006d1e5ddb28a2215d1e74e215b928f2c9ac2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use axum::{
    extract::{Request, State},
    middleware::Next,
    response::Response,
};

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

// Expires messages and channels before each request.
pub async fn middleware(
    State(app): State<App>,
    RequestedAt(expired_at): RequestedAt,
    req: Request,
    next: Next,
) -> Result<Response, Internal> {
    app.logins().expire(&expired_at).await?;
    app.events().expire(&expired_at).await?;
    app.channels().expire(&expired_at).await?;
    Ok(next.run(req).await)
}