Skip to content

Commit

Permalink
fix(auth): Allow sign up, confirm sign up, and auto sign in while Sig…
Browse files Browse the repository at this point in the history
…ningIn (#2958)
  • Loading branch information
tylerjroach authored Nov 26, 2024
1 parent 53c48b8 commit 8f61b1d
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,9 @@ internal class RealAWSCognitoAuthPlugin(
is AuthenticationState.NotConfigured -> onError.accept(
InvalidUserPoolConfigurationException()
)
is AuthenticationState.SignedIn, is AuthenticationState.SignedOut -> GlobalScope.launch {
else -> GlobalScope.launch {
_signUp(username, password, options, onSuccess, onError)
}
else -> onError.accept(InvalidStateException())
}
}
}
Expand Down Expand Up @@ -309,10 +308,9 @@ internal class RealAWSCognitoAuthPlugin(
is AuthenticationState.NotConfigured -> onError.accept(
InvalidUserPoolConfigurationException()
)
is AuthenticationState.SignedIn, is AuthenticationState.SignedOut -> GlobalScope.launch {
else -> GlobalScope.launch {
_confirmSignUp(username, confirmationCode, authState.authSignUpState, options, onSuccess, onError)
}
else -> onError.accept(InvalidStateException())
}
}
}
Expand Down Expand Up @@ -381,6 +379,29 @@ internal class RealAWSCognitoAuthPlugin(
else -> onError.accept(InvalidStateException())
}
}
is AuthenticationState.SigningIn -> {
val token = StateChangeListenerToken()
authStateMachine.listen(
token,
{ authState ->
when (authState.authNState) {
is AuthenticationState.SignedOut -> {
authStateMachine.cancel(token)
when (val signUpState = authState.authSignUpState) {
is SignUpState.SignedUp -> GlobalScope.launch {
_autoSignIn(signUpState.signUpData, onSuccess, onError)
}
else -> onError.accept(InvalidStateException())
}
}
else -> Unit
}
},
{
authStateMachine.send(AuthenticationEvent(AuthenticationEvent.EventType.CancelSignIn()))
}
)
}
else -> onError.accept(InvalidStateException())
}
}
Expand Down

0 comments on commit 8f61b1d

Please sign in to comment.