Skip to content

Commit e181875

Browse files
authored
fix(auth): Fix HostedUI signout cancellation issue (#2834)
1 parent fe52c26 commit e181875

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt

+13
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,7 @@ internal class RealAWSCognitoAuthPlugin(
18801880

18811881
private fun _signOut(sendHubEvent: Boolean = true, onComplete: Consumer<AuthSignOutResult>) {
18821882
val token = StateChangeListenerToken()
1883+
var cancellationException: UserCancelledException? = null
18831884
authStateMachine.listen(
18841885
token,
18851886
{ authState ->
@@ -1921,6 +1922,18 @@ internal class RealAWSCognitoAuthPlugin(
19211922
)
19221923
)
19231924
}
1925+
authNState is AuthenticationState.SigningOut -> {
1926+
val state = authNState.signOutState
1927+
if (state is SignOutState.Error && state.exception is UserCancelledException) {
1928+
cancellationException = state.exception
1929+
}
1930+
}
1931+
authNState is AuthenticationState.SignedIn && cancellationException != null -> {
1932+
authStateMachine.cancel(token)
1933+
cancellationException?.let {
1934+
onComplete.accept(AWSCognitoAuthSignOutResult.FailedSignOut(it))
1935+
}
1936+
}
19241937
else -> {
19251938
// No - op
19261939
}

aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignOutState.kt

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
package com.amplifyframework.statemachine.codegen.states
1717

18+
import com.amplifyframework.auth.cognito.exceptions.service.UserCancelledException
1819
import com.amplifyframework.auth.cognito.isAuthEvent
1920
import com.amplifyframework.auth.cognito.isSignOutEvent
2021
import com.amplifyframework.statemachine.State
@@ -86,7 +87,15 @@ internal sealed class SignOutState : State {
8687
}
8788
is SignOutEvent.EventType.UserCancelled -> {
8889
val action = signOutActions.userCancelledAction(signOutEvent)
89-
StateResolution(Error(Exception("User Cancelled")), listOf(action))
90+
StateResolution(
91+
Error(
92+
UserCancelledException(
93+
"The user cancelled the sign-out attempt, so it did not complete.",
94+
"To recover: catch this error, and attempt the sign out again."
95+
)
96+
),
97+
listOf(action)
98+
)
9099
}
91100
else -> defaultResolution
92101
}

0 commit comments

Comments
 (0)