use crate::to_login; use tide::{Middleware, Next, Request}; pub(crate) struct AuthMiddleware; #[derive(serde::Deserialize, serde::Serialize)] pub struct UserInfo { pub(crate) username: String, } #[async_trait::async_trait] impl Middleware for AuthMiddleware where State: Clone + Send + Sync + 'static, { async fn handle(&self, mut request: Request, next: Next<'_, State>) -> tide::Result { let path = request.url().path().to_string(); let session = request.session_mut(); if session.get::("user").is_some() { return Ok(next.run(request).await); } to_login(session, &path) } }