File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
http4k-example/src/main/kotlin/za/co/ee/learning/domain/users/usecases Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments