From f2f820370efbd5c6d0f304f781284a9f68990e21 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 11 Sep 2024 22:43:14 -0400 Subject: Wrap the database pool in an App struct. This is a jumping-off point for adding logic that needs more than just the DB for state, such as chat message handling. The name sucks, but it's the best I've got. --- src/login/extract/login.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/login/extract') diff --git a/src/login/extract/login.rs b/src/login/extract/login.rs index da0a90e..4155ec2 100644 --- a/src/login/extract/login.rs +++ b/src/login/extract/login.rs @@ -3,9 +3,9 @@ use axum::{ http::{request::Parts, StatusCode}, response::{IntoResponse, Response}, }; -use sqlx::sqlite::SqlitePool; use crate::{ + app::App, clock::RequestedAt, error::InternalError, login::{ @@ -15,13 +15,10 @@ use crate::{ }; #[async_trait::async_trait] -impl FromRequestParts for Login { +impl FromRequestParts for Login { type Rejection = LoginError; - async fn from_request_parts( - parts: &mut Parts, - state: &SqlitePool, - ) -> Result { + async fn from_request_parts(parts: &mut Parts, state: &App) -> Result { // After Rust 1.82 (and #[feature(min_exhaustive_patterns)] lands on // stable), the following can be replaced: // @@ -31,8 +28,8 @@ impl FromRequestParts for Login { let secret = identity_token.secret().ok_or(LoginError::Forbidden)?; - let db = State::::from_request_parts(parts, state).await?; - let mut tx = db.begin().await?; + let app = State::::from_request_parts(parts, state).await?; + let mut tx = app.db.begin().await?; tx.tokens().expire(requested_at).await?; let login = tx.tokens().validate(secret, requested_at).await?; tx.commit().await?; -- cgit v1.2.3