Skip to content

fix(auth): fetch device metadata from credential store for remember and forgetDevice #2601

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

Merged
merged 9 commits into from
Oct 11, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ import com.amplifyframework.statemachine.StateChangeListenerToken
import com.amplifyframework.statemachine.codegen.data.AmplifyCredential
import com.amplifyframework.statemachine.codegen.data.AuthChallenge
import com.amplifyframework.statemachine.codegen.data.AuthConfiguration
import com.amplifyframework.statemachine.codegen.data.DeviceMetadata
import com.amplifyframework.statemachine.codegen.data.FederatedToken
import com.amplifyframework.statemachine.codegen.data.HostedUIErrorData
import com.amplifyframework.statemachine.codegen.data.SignInData
Expand Down Expand Up @@ -1223,12 +1222,14 @@ internal class RealAWSCognitoAuthPlugin(
authStateMachine.getCurrentState { authState ->
when (val state = authState.authNState) {
is AuthenticationState.SignedIn -> {
updateDevice(
(state.deviceMetadata as? DeviceMetadata.Metadata)?.deviceKey,
DeviceRememberedStatusType.Remembered,
onSuccess,
onError
)
GlobalScope.launch {
updateDevice(
authEnvironment.getDeviceMetadata(state.signedInData.username)?.deviceKey,
DeviceRememberedStatusType.Remembered,
onSuccess,
onError
)
}
}
is AuthenticationState.SignedOut -> {
onError.accept(SignedOutException())
Expand Down Expand Up @@ -1276,8 +1277,11 @@ internal class RealAWSCognitoAuthPlugin(
when (val authState = authState.authNState) {
is AuthenticationState.SignedIn -> {
if (device.id.isEmpty()) {
val deviceKey = (authState.deviceMetadata as? DeviceMetadata.Metadata)?.deviceKey
updateDevice(deviceKey, DeviceRememberedStatusType.NotRemembered, onSuccess, onError)
GlobalScope.launch {
val deviceKey = authEnvironment.getDeviceMetadata(authState.signedInData.username)
?.deviceKey
updateDevice(deviceKey, DeviceRememberedStatusType.NotRemembered, onSuccess, onError)
}
} else {
updateDevice(device.id, DeviceRememberedStatusType.NotRemembered, onSuccess, onError)
}
Expand Down