Skip to content

Commit

Permalink
refactor: update usage of check user exist in login method
Browse files Browse the repository at this point in the history
now we check for the return type and return more apropriate information to the user
  • Loading branch information
Atheer2104 committed Mar 17, 2024
1 parent 9a2a14b commit 2c50f06
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions auth/src/server/auth_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ impl Auth for AuthenticationService {
error_details.add_bad_request_violation("password", "password field is empty");
}

if check_user_exists(login_request, &self.db_pool)
.await
.is_err()
{
error_details.set_localized_message("en-US", "The login information you provided is not valid. Please check your username and password and try again.");
}

if error_details.has_bad_request_violations() {
let status = Status::with_error_details(
Code::InvalidArgument,
Expand All @@ -59,6 +52,18 @@ impl Auth for AuthenticationService {
return Err(status);
}

match check_user_exists(login_request, &self.db_pool).await {
Ok(_) => (),
Err(e) => match e {
CheckUserExistsError::NonExistingUser => {
return Err(Status::unauthenticated(e.to_string()))
}
CheckUserExistsError::DatabaseError(_) => {
return Err(Status::internal(e.to_string()))
}
},
};

let token = Token {
access_token: "654321".into(),
};
Expand Down

0 comments on commit 2c50f06

Please sign in to comment.