Skip to content

Commit

Permalink
fix(auth): Fix HostedUI signout cancellation issue (#2834)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerjroach authored May 31, 2024
1 parent fe52c26 commit e181875
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,7 @@ internal class RealAWSCognitoAuthPlugin(

private fun _signOut(sendHubEvent: Boolean = true, onComplete: Consumer<AuthSignOutResult>) {
val token = StateChangeListenerToken()
var cancellationException: UserCancelledException? = null
authStateMachine.listen(
token,
{ authState ->
Expand Down Expand Up @@ -1921,6 +1922,18 @@ internal class RealAWSCognitoAuthPlugin(
)
)
}
authNState is AuthenticationState.SigningOut -> {
val state = authNState.signOutState
if (state is SignOutState.Error && state.exception is UserCancelledException) {
cancellationException = state.exception
}
}
authNState is AuthenticationState.SignedIn && cancellationException != null -> {
authStateMachine.cancel(token)
cancellationException?.let {
onComplete.accept(AWSCognitoAuthSignOutResult.FailedSignOut(it))
}
}
else -> {
// No - op
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package com.amplifyframework.statemachine.codegen.states

import com.amplifyframework.auth.cognito.exceptions.service.UserCancelledException
import com.amplifyframework.auth.cognito.isAuthEvent
import com.amplifyframework.auth.cognito.isSignOutEvent
import com.amplifyframework.statemachine.State
Expand Down Expand Up @@ -86,7 +87,15 @@ internal sealed class SignOutState : State {
}
is SignOutEvent.EventType.UserCancelled -> {
val action = signOutActions.userCancelledAction(signOutEvent)
StateResolution(Error(Exception("User Cancelled")), listOf(action))
StateResolution(
Error(
UserCancelledException(
"The user cancelled the sign-out attempt, so it did not complete.",
"To recover: catch this error, and attempt the sign out again."
)
),
listOf(action)
)
}
else -> defaultResolution
}
Expand Down

0 comments on commit e181875

Please sign in to comment.