fix(auth): Fix Device Metadata migration if alised userId was used #2963
+226
−24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Amplify v1 (or standalone AWS Android SDK) migrations to Amplify v2 do not migrate all required data in some cases. This results in token refresh failures.
Requirements for Issue:
Cause of Bug
Amplify v2 pulls "LastAuthUserId" from the legacy (v1) credential store. This value is the alias (ex: email address), not necessarily the actual userId. This results in a failed lookup for device metadata. Device metadata will not be migrated to the new credential store format, and the existing file remains untouched on the device.
Additional Bug Discovered
We are only migrating device metadata for the "LastAuthUserId". We shouldn't have this restriction.
Issue #, if available:
#2929
Description of changes:
We can pull a list of userIds (not aliased) with device metadata stored on the device, by scanning shared preference files.
We then iterate through each of those userIds, and lookup the legacy device metadata. If we do not currently have device metadata for the given userId in the Amplify v2 credential store, we will now properly migrate the device metadata from the legacy keystore.
How did you test these changes?
(Please add a line here how the changes were tested)
Documentation update required?
General Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.