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 for when loading credentials the success/error is fired twice #2184

Merged
merged 6 commits into from Dec 20, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -56,9 +56,9 @@ internal class CredentialStoreClient(configuration: AuthConfiguration, context:
) {
var capturedSuccess: Result<AmplifyCredential>? = null
var capturedError: Exception? = null
val token = StateChangeListenerToken()
var token: StateChangeListenerToken? = StateChangeListenerToken()
credentialStoreStateMachine.listen(
token,
token as StateChangeListenerToken,
gpanshu marked this conversation as resolved.
Show resolved Hide resolved
{ storeState ->
logger.verbose("Credential Store State Change: $storeState")

Expand All @@ -72,11 +72,12 @@ internal class CredentialStoreClient(configuration: AuthConfiguration, context:
is CredentialStoreState.Idle -> {
val success = capturedSuccess
val error = capturedError
if (success != null) {
credentialStoreStateMachine.cancel(token)
if (success != null && token != null) {
credentialStoreStateMachine.cancel(token as StateChangeListenerToken)
token = null
onSuccess(success)
} else if (error != null) {
credentialStoreStateMachine.cancel(token)
} else if (error != null && token != null) {
mattcreaser marked this conversation as resolved.
Show resolved Hide resolved
credentialStoreStateMachine.cancel(token as StateChangeListenerToken)
onError(error)
}
}
Expand Down