Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): Fix HostedUI signout cancellation issue #2834

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading