aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.32k stars 248 forks source link

Remember my device require re-sign in after forget my device is executed else receive exception #4536

Closed dkliss closed 8 months ago

dkliss commented 8 months ago

Description

Hi,

Once a user has Signed In, I have an option for user to "Remember my device or Forget my device" which uses below functions.

Future<void> rememberCurrentDevice() async {
    try {
      await Amplify.Auth.rememberDevice();
      safePrint('Remember device succeeded');
    } on AuthException catch (e) {
      safePrint('Remember device failed with error: $e');
    }
  }

  Future<void> forgetCurrentDevice() async {
    try {
      await Amplify.Auth.forgetDevice();
      safePrint('Forget device succeeded');
    } on AuthException catch (e) {
      safePrint('Forget device failed with error: $e');
    }
  }

The Cognito is set to

"User opt-in"
Trust remembered devices to suppress MFA
Yes

If I select remember my device, then sign out and sign in again, MFA is not required, which works as expected.

However, if I do below sequence below I get exception:

  1. Sign In with MFA.
  2. Run "Remember my device". Works as expected.
  3. Run "Forget my device". Works as expected.
  4. Then again Run "Remember my device" and I get exception below:
flutter: Remember device failed with error: DeviceNotTrackedException {
  "message": "This device does not have an id, either it was never tracked or previously forgotten."
}
  1. Above exception does not go away unless I sIgn-out and sign-in again.
  2. And the same issue repeat if I run steps 1,2 3, & after sign out and sign in again.

So in summary, after i i select forget device, I cannot run remember my device again without signing out and sign in again? Is this expected? Seems not correct unless I am missing something.

To reproduce:

  1. Enable Device Tracking.
  2. Sign in with MFA
  3. Select remember my device. SUCCESSFUL.
  4. Select forget my device. SUCCESSFUL.
  5. Again Select remember my device. FAILS with EXCEPTION as discussed. Expected this to work.

Categories

Steps to Reproduce

No response

Screenshots

No response

Platforms

Flutter Version

3.19.1

Amplify Flutter Version

1.6.1

Deployment Method

Amplify CLI

Schema

No response

khatruong2009 commented 8 months ago

Hi @dkliss, this is expected behavior. Calling forgetDevice wipes the device keys that rememberDevice requires in order to save the device. This leads to the DeviceNotTrackedException that you're receiving. In order to get the device keys again, the user would have to log out and log in again. I'm going to close this issue now but if you have any further questions or other issues, feel free to reopen this issue or open a new one, thanks.

dkliss commented 8 months ago

Hi @dkliss, this is expected behavior. Calling forgetDevice wipes the device keys that rememberDevice requires in order to save the device. This leads to the DeviceNotTrackedException that you're receiving. In order to get the device keys again, the user would have to log out and log in again. I'm going to close this issue now but if you have any further questions or other issues, feel free to reopen this issue or open a new one, thanks.

Thanks you @khatruong2009 for confirming. Seems like this is how it is supposed to work.