use crate::to_login; use tide::{Middleware, Next, Request}; pub(crate) struct AuthMiddleware; #[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(); let logged_in: bool = session.get("logged_in").unwrap_or(false); if logged_in { return Ok(next.run(request).await); } to_login(session, &path) } }