diff options
Diffstat (limited to 'src/api/users.rs')
-rw-r--r-- | src/api/users.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/api/users.rs b/src/api/users.rs index 0cac406..6eb2a39 100644 --- a/src/api/users.rs +++ b/src/api/users.rs @@ -9,6 +9,7 @@ use axum::{ use axum_extra::{ headers::{authorization::Basic, Authorization}, routing::Resource, + typed_header::TypedHeaderRejection, TypedHeader, }; use serde::{Deserialize, Serialize}; @@ -48,8 +49,15 @@ pub struct RegisterSchema { pub async fn login( State(state): State<AppState>, - TypedHeader(Authorization(basic)): TypedHeader<Authorization<Basic>>, + auth: Result<TypedHeader<Authorization<Basic>>, TypedHeaderRejection>, + claims: Option<RefreshClaims>, ) -> Result<(AccessClaims, RefreshClaims), Error> { + if let Some(refresh_claims) = claims { + return Ok((refresh_claims.refresh(), refresh_claims)); + } + + let TypedHeader(Authorization(basic)) = auth?; + let user_id = sqlx::query_scalar!("SELECT id FROM user_ WHERE email = $1", basic.username()) .fetch_optional(&state.pool) .await? |