furaiev / amazon-cognito-identity-dart-2

Unofficial Amazon Cognito Identity Provider Dart SDK, to easily add user sign-up and sign-in to your mobile and web apps with AWS.
MIT License
182 stars 113 forks source link

New device_key on every app open #216

Closed nourski closed 1 year ago

nourski commented 1 year ago

I have enabled remembering device to suppress MFA. It seems to be working really well except the device key seems to change every time the app is closed and reopened which means MFA is re-triggered every time the app is opened which defeats the purpose of remembering the device.

Please see attached device logs from Cognito for reference. I noticed that if I logout and log back in without restarting the app, the same device token is maintained, it only seems to regenerate when the app is freshly opened.

Screen Shot 2022-10-31 at 7 00 10 PM
nourski commented 1 year ago

Was able to figure out the issue and solution in case anyone else runs into this:

Had to go the custom storage route and deserialize the stored string when retrieving the value. I.e.:

class CustomStorage extends CognitoStorage {

  ...

  @override
  Future getItem(String key) async {
    final value = await _storage.read(key: key);
    return value?.replaceAll('"', '');
  }

  ... 
}