diff --git a/packages/amplify_core/doc/lib/auth.dart b/packages/amplify_core/doc/lib/auth.dart index a69fde0f6c..ac51f3da61 100644 --- a/packages/amplify_core/doc/lib/auth.dart +++ b/packages/amplify_core/doc/lib/auth.dart @@ -483,6 +483,17 @@ Future forgetSpecificDevice(AuthDevice myDevice) async { } // #enddocregion forget-specific-device +// #docregion fetch-current-device +Future fetchCurrentUserDevice() async { + try { + final device = await Amplify.Auth.fetchCurrentDevice(); + safePrint('Device: $device'); + } on AuthException catch (e) { + safePrint('Fetch current device failed with error: $e'); + } +} +// #enddocregion fetch-current-device + // #docregion fetch-devices Future fetchAllDevices() async { try { diff --git a/packages/amplify_core/lib/src/category/amplify_auth_category.dart b/packages/amplify_core/lib/src/category/amplify_auth_category.dart index 4a23528d70..bf3bfd27ff 100644 --- a/packages/amplify_core/lib/src/category/amplify_auth_category.dart +++ b/packages/amplify_core/lib/src/category/amplify_auth_category.dart @@ -1355,6 +1355,37 @@ class AuthCategory extends AmplifyCategory { () => defaultPlugin.rememberDevice(), ); + /// {@template amplify_core.amplify_auth_category.fetch_current_device} + /// Retrieves the current device. + /// + /// For more information about device tracking, see the + /// [Amplify docs](https://docs.amplify.aws/flutter/build-a-backend/auth/manage-users/manage-devices/#fetch-current-device). + /// + /// ## Examples + /// + /// + /// ```dart + /// import 'package:amplify_auth_cognito/amplify_auth_cognito.dart'; + /// import 'package:amplify_flutter/amplify_flutter.dart'; + /// ``` + /// + /// + /// ```dart + /// Future getCurrentUserDevice() async { + /// try { + /// final device = await Amplify.Auth.fetchCurrentDevice(); + /// safePrint('Device: $device'); + /// } on AuthException catch (e) { + /// safePrint('Fetch current device failed with error: $e'); + /// } + /// } + /// ``` + /// {@endtemplate} + Future fetchCurrentDevice() => identifyCall( + AuthCategoryMethod.fetchCurrentDevice, + () => defaultPlugin.fetchCurrentDevice(), + ); + /// {@template amplify_core.amplify_auth_category.forget_device} /// Forgets the current device. /// diff --git a/packages/amplify_core/lib/src/http/amplify_category_method.dart b/packages/amplify_core/lib/src/http/amplify_category_method.dart index a0c978594b..97ee62251e 100644 --- a/packages/amplify_core/lib/src/http/amplify_category_method.dart +++ b/packages/amplify_core/lib/src/http/amplify_category_method.dart @@ -52,7 +52,8 @@ enum AuthCategoryMethod with AmplifyCategoryMethod { setMfaPreference('49'), getMfaPreference('50'), setUpTotp('51'), - verifyTotpSetup('52'); + verifyTotpSetup('52'), + fetchCurrentDevice('59'); const AuthCategoryMethod(this.method); diff --git a/packages/amplify_core/lib/src/plugin/amplify_auth_plugin_interface.dart b/packages/amplify_core/lib/src/plugin/amplify_auth_plugin_interface.dart index 43e74853f3..80521de18d 100644 --- a/packages/amplify_core/lib/src/plugin/amplify_auth_plugin_interface.dart +++ b/packages/amplify_core/lib/src/plugin/amplify_auth_plugin_interface.dart @@ -189,6 +189,11 @@ abstract class AuthPluginInterface extends AmplifyPluginInterface { throw UnimplementedError('forgetDevice() has not been implemented.'); } + /// {@macro amplify_core.amplify_auth_category.fetch_current_device} + Future fetchCurrentDevice() { + throw UnimplementedError('fetchCurrentDevice() has not been implemented.'); + } + /// {@macro amplify_core.amplify_auth_category.fetch_devices} Future> fetchDevices() { throw UnimplementedError('fetchDevices() has not been implemented.');