diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-09-11 22:43:14 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-09-12 00:26:04 -0400 |
| commit | f2f820370efbd5c6d0f304f781284a9f68990e21 (patch) | |
| tree | 7fb25e676dcd8dc694d0cec4df2cc04cab1120ac /src/login/extract | |
| parent | 8a4e25c2a7d6235d726499d43fd1721104314e86 (diff) | |
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.
Diffstat (limited to 'src/login/extract')
| -rw-r--r-- | src/login/extract/login.rs | 13 |
1 files changed, 5 insertions, 8 deletions
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<SqlitePool> for Login { +impl FromRequestParts<App> for Login { type Rejection = LoginError<InternalError>; - async fn from_request_parts( - parts: &mut Parts, - state: &SqlitePool, - ) -> Result<Self, Self::Rejection> { + async fn from_request_parts(parts: &mut Parts, state: &App) -> Result<Self, Self::Rejection> { // After Rust 1.82 (and #[feature(min_exhaustive_patterns)] lands on // stable), the following can be replaced: // @@ -31,8 +28,8 @@ impl FromRequestParts<SqlitePool> for Login { let secret = identity_token.secret().ok_or(LoginError::Forbidden)?; - let db = State::<SqlitePool>::from_request_parts(parts, state).await?; - let mut tx = db.begin().await?; + let app = State::<App>::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?; |
