-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Fix validation approach in # (#99)
- Loading branch information
1 parent
fd11391
commit 05d1041
Showing
11 changed files
with
249 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 31 additions & 27 deletions
58
...sentation/src/commonMain/kotlin/io/spherelabs/authpresentation/signin/SignInMiddleware.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,43 @@ | ||
package io.spherelabs.authpresentation.signin | ||
|
||
import io.spherelabs.authdomain.HasCurrentUserExist | ||
import io.spherelabs.authdomain.NameValidation | ||
import io.spherelabs.authdomain.PasswordValidation | ||
import io.spherelabs.authdomain.SignInWithEmailAndPassword | ||
import io.spherelabs.meteor.middleware.Middleware | ||
|
||
class SignInMiddleware( | ||
private val signInWithEmailAndPassword: SignInWithEmailAndPassword, | ||
private val hasCurrentUserExist: HasCurrentUserExist | ||
private val signInWithEmailAndPassword: SignInWithEmailAndPassword, | ||
private val hasCurrentUserExist: HasCurrentUserExist | ||
) : Middleware<SignInState, SignInWish> { | ||
|
||
override suspend fun process( | ||
state: SignInState, | ||
wish: SignInWish, | ||
next: suspend (SignInWish) -> Unit | ||
) { | ||
when (wish) { | ||
SignInWish.SignIn -> { | ||
val result = signInWithEmailAndPassword.execute(state.email, state.password) | ||
override suspend fun process( | ||
state: SignInState, | ||
wish: SignInWish, | ||
next: suspend (SignInWish) -> Unit, | ||
) { | ||
when (wish) { | ||
SignInWish.SignIn -> { | ||
val result = signInWithEmailAndPassword.execute(state.email, state.password) | ||
|
||
result | ||
.onSuccess { next.invoke(SignInWish.SignInSuccess) } | ||
.onFailure { | ||
val failureMessage = it.message ?: "Error is occurred." | ||
next.invoke(SignInWish.SignInFailure(failureMessage)) | ||
} | ||
} | ||
is SignInWish.CheckCurrentUser -> { | ||
runCatching { hasCurrentUserExist.execute() } | ||
.onSuccess { next.invoke(SignInWish.HasCurrentUser(it)) } | ||
.onFailure { | ||
val failureMessage = it.message ?: "Error is occurred." | ||
next.invoke(SignInWish.SignInFailure(failureMessage)) | ||
} | ||
} | ||
else -> {} | ||
result | ||
.onSuccess { next.invoke(SignInWish.SignInSuccess) } | ||
.onFailure { | ||
val failureMessage = it.message ?: "Error is occurred." | ||
next.invoke(SignInWish.SignInFailure(failureMessage)) | ||
} | ||
} | ||
|
||
is SignInWish.CheckCurrentUser -> { | ||
runCatching { hasCurrentUserExist.execute() } | ||
.onSuccess { next.invoke(SignInWish.HasCurrentUser(it)) } | ||
.onFailure { | ||
val failureMessage = it.message ?: "Error is occurred." | ||
next.invoke(SignInWish.SignInFailure(failureMessage)) | ||
} | ||
} | ||
|
||
else -> {} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.