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/routes.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/login/routes.rs') diff --git a/src/login/routes.rs b/src/login/routes.rs index c30bcb1..9cefe38 100644 --- a/src/login/routes.rs +++ b/src/login/routes.rs @@ -5,16 +5,15 @@ use axum::{ routing::post, Router, }; -use sqlx::sqlite::SqlitePool; -use crate::{clock::RequestedAt, error::InternalError}; +use crate::{app::App, clock::RequestedAt, error::InternalError}; use super::{ extract::IdentityToken, repo::{logins::Provider as _, tokens::Provider as _}, }; -pub fn router() -> Router { +pub fn router() -> Router { Router::new() .route("/login", post(on_login)) .route("/logout", post(on_logout)) @@ -27,12 +26,12 @@ struct LoginRequest { } async fn on_login( - State(db): State, + State(app): State, RequestedAt(now): RequestedAt, identity: IdentityToken, Form(form): Form, ) -> Result { - let mut tx = db.begin().await?; + let mut tx = app.db.begin().await?; // Spelling the following in the more conventional form, // if let Some(…) = create().await? {} @@ -88,11 +87,11 @@ impl IntoResponse for LoginResponse { } async fn on_logout( - State(db): State, + State(app): State, identity: IdentityToken, ) -> Result { if let Some(secret) = identity.secret() { - let mut tx = db.begin().await?; + let mut tx = app.db.begin().await?; tx.tokens().revoke(secret).await?; tx.commit().await?; } -- cgit v1.2.3