Instantly share code, notes, and snippets.

Embed
What would you like to do?
fun executeGitHubLogin(action: LoginAction, dispatch: DispatchFunction) {
val loginTaskListenerMiddleware = LoginTaskListenerMiddleware()
val authTask = UserLoginTask(loginTaskListenerMiddleware,
action.userName,
action.password )
authTask.execute()
dispatch(LoginStartedAction(action.userName))
}
interface LoginTaskListenerInterface {
fun onFinished(result: LoginCompletedAction,store: Store<StateType>)
}
class LoginTaskListenerMiddleware : LoginTaskListenerInterface {
override fun onFinished(result: LoginCompletedAction, store: Store<StateType>) {
if (result.loginStatus == LoggedInState.loggedIn ) {
result.token?.let {
// Login succeed, do the next work
}
} else {
result.message?.let{
// Login failed, show an error message
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment