diff options
Diffstat (limited to 'src/auth.rs')
-rw-r--r-- | src/auth.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/auth.rs b/src/auth.rs index 6bf0ddf..909534e 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -9,6 +9,7 @@ use axum_extra::{ headers::{authorization::Basic, Authorization}, TypedHeader, }; +use sqlx::PgPool; use uuid::Uuid; use crate::state::AppState; @@ -32,11 +33,11 @@ pub fn router() -> axum::Router<AppState> { } pub async fn issue( - State(state): State<AppState>, + State(pool): State<PgPool>, Account { id, password }: Account, ) -> Result<(AccessClaims, RefreshClaims), Error> { let p: String = sqlx::query_scalar!("SELECT password_hash FROM credential WHERE id = $1", id) - .fetch_optional(&state.pool) + .fetch_optional(&pool) .await? .ok_or(Error::LoginInvalid)?; @@ -58,10 +59,13 @@ pub struct Account { } #[async_trait] -impl FromRequestParts<AppState> for Account { +impl<S> FromRequestParts<S> for Account +where + S: Send + Sync, +{ type Rejection = Error; - async fn from_request_parts(parts: &mut Parts, _: &AppState) -> Result<Self, Self::Rejection> { + async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> { let TypedHeader(Authorization(basic)) = parts.extract::<TypedHeader<Authorization<Basic>>>().await?; @@ -82,7 +86,6 @@ mod tests { Router, }; use axum_extra::headers::{authorization::Credentials, Authorization}; - use sqlx::PgPool; use tower::ServiceExt; use crate::tests::{setup_test_env, TestResult}; |