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/routes.rs | |
| 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/routes.rs')
| -rw-r--r-- | src/login/routes.rs | 13 |
1 files changed, 6 insertions, 7 deletions
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<SqlitePool> { +pub fn router() -> Router<App> { 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<SqlitePool>, + State(app): State<App>, RequestedAt(now): RequestedAt, identity: IdentityToken, Form(form): Form<LoginRequest>, ) -> Result<impl IntoResponse, InternalError> { - 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<SqlitePool>, + State(app): State<App>, identity: IdentityToken, ) -> Result<impl IntoResponse, InternalError> { 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?; } |
