Skip to content

Commit 25eb60b

Browse files
Paul ScottPaul Scott
authored andcommitted
Final change based on PR comments
1 parent 40acc63 commit 25eb60b

File tree

1 file changed

+7
-7
lines changed
  • http4k-example/src/main/kotlin/za/co/ee/learning/domain/users/usecases

1 file changed

+7
-7
lines changed

http4k-example/src/main/kotlin/za/co/ee/learning/domain/users/usecases/Authenticate.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class Authenticate(
3232
val validatedRequest = validate(request).bind()
3333
val userOption = userRepository.findByEmail(validatedRequest.email).bind()
3434
val user = userOption.toEither { DomainError.InvalidCredentials }.bind()
35-
val pwdHashString = user.passwordHash.bind()
36-
val authenticatedUser = authenticateUser(user, pwdHashString, validatedRequest).bind()
35+
val authenticatedUser = authenticateUser(user, validatedRequest).bind()
3736
createToken(authenticatedUser).bind()
3837
}
3938

@@ -59,13 +58,14 @@ class Authenticate(
5958

6059
private fun authenticateUser(
6160
user: User,
62-
passwordHash: String,
6361
validatedRequest: AuthenticateRequest,
64-
): DomainResult<User> {
65-
if (passwordProvider.matches(validatedRequest.password, passwordHash)) {
66-
return user.right()
62+
): DomainResult<User> = either {
63+
val passwordHashString = user.passwordHash.bind()
64+
if (passwordProvider.matches(validatedRequest.password, passwordHashString)) {
65+
user
66+
} else {
67+
raise(DomainError.InvalidCredentials)
6768
}
68-
return DomainError.InvalidCredentials.left()
6969
}
7070

7171
private fun createToken(authenticatedUser: User): DomainResult<AuthenticateResponse> = either {

0 commit comments

Comments
 (0)