diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2022-09-15 14:31:30 +0000 |
|---|---|---|
| committer | Santo Cariotti <santo@dcariotti.me> | 2022-09-15 14:31:30 +0000 |
| commit | 3aae8ec6da9c1a1a5dffb4e8cd2ffc2560e5b9f1 (patch) | |
| tree | 5c394957d980165efc174f58c56af7a1d90a472a /src/routes/auth.rs | |
| parent | ef8a0f433878b01cd247a009ae93d95b559d0abc (diff) | |
Add `JsonCreate` trait which is a Json with 201 status
Diffstat (limited to 'src/routes/auth.rs')
| -rw-r--r-- | src/routes/auth.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/routes/auth.rs b/src/routes/auth.rs index 5c9b293..7cd16ad 100644 --- a/src/routes/auth.rs +++ b/src/routes/auth.rs @@ -3,6 +3,7 @@ use crate::models::{ auth::{AuthBody, Claims, LoginCredentials, SignUpForm}, user::User, }; +use crate::routes::JsonCreate; use axum::{routing::post, Json, Router}; /// Create routes for `/v1/auth/` namespace @@ -27,7 +28,7 @@ async fn make_login(Json(payload): Json<LoginCredentials>) -> Result<Json<AuthBo } /// Create a new user -async fn signup(Json(payload): Json<SignUpForm>) -> Result<Json<AuthBody>, AppError> { +async fn signup(Json(payload): Json<SignUpForm>) -> Result<JsonCreate<AuthBody>, AppError> { if payload.password1 != payload.password2 { return Err(AppError::BadRequest( "The inserted passwords do not match".to_string(), @@ -51,5 +52,5 @@ async fn signup(Json(payload): Json<SignUpForm>) -> Result<Json<AuthBody>, AppEr let claims = Claims::new(user.id); let token = claims.get_token()?; - Ok(Json(AuthBody::new(token))) + Ok(JsonCreate(AuthBody::new(token))) } |
