Skip to content

Commit

Permalink
Merge pull request #218 from NIAEFEUP/fix/invalid-credentials-on-emai…
Browse files Browse the repository at this point in the history
…l-doesnt-exist

Fixed invalid error message
  • Loading branch information
PedroOliveira42 authored Feb 26, 2025
2 parents d7e45c4 + 864af85 commit b77552a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class AccountService(

fun doesAccountExist(id: Long): Boolean = repository.findByIdOrNull(id) != null

fun doesAccountExist(email: String): Boolean = repository.findByEmail(email) != null

fun updateAccountById(id: Long, dto: UpdateAccountDto): Account {
val account = getAccountById(id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class AuthService(
}

fun authenticate(email: String, password: String): Account {
if (!accountService.doesAccountExist(email)) throw InvalidBearerTokenException(ErrorMessages.invalidCredentials)
val account = accountService.getAccountByEmail(email)
if (!passwordEncoder.matches(password, account.password)) {
throw InvalidBearerTokenException(ErrorMessages.invalidCredentials)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ class AuthControllerTest @Autowired constructor(
)

).andExpectAll(
status().isNotFound,
jsonPath("$.errors[0].message").value("account not found with email [email protected]")
status().isUnauthorized,
jsonPath("$.errors[0].message").value("invalid credentials")
).andDocumentErrorResponse(documentation, hasRequestPayload = true)
}

Expand Down

0 comments on commit b77552a

Please sign in to comment.