diff options
Diffstat (limited to 'src/routes/auth.rs')
| -rw-r--r-- | src/routes/auth.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/routes/auth.rs b/src/routes/auth.rs index 37c41b2..b667b97 100644 --- a/src/routes/auth.rs +++ b/src/routes/auth.rs @@ -1,7 +1,7 @@ use crate::errors::AppError; use crate::models::{ - auth::{AuthBody, Claims}, - user::{User, UserCreate}, + auth::{AuthBody, Claims, LoginCredentials}, + user::User, }; use axum::{routing::post, Json, Router}; @@ -12,14 +12,14 @@ pub fn create_route() -> Router { /// Make login. Check if a user with the email and password passed in request body exists into the /// database -async fn make_login(Json(payload): Json<UserCreate>) -> Result<Json<AuthBody>, AppError> { - let user = User::new(payload.email, payload.password); +async fn make_login(Json(payload): Json<LoginCredentials>) -> Result<Json<AuthBody>, AppError> { + let user = User::new(String::new(), payload.username, payload.password); match User::find(user).await { Ok(user) => { let claims = Claims::new(user.id); let token = claims.get_token()?; Ok(Json(AuthBody::new(token))) } - Err(_) => Err(AppError::NotFound), + Err(_) => Err(AppError::NotFound("User not found".to_string())), } } |
