File tree Expand file tree Collapse file tree 4 files changed +49
-1
lines changed Expand file tree Collapse file tree 4 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -483,6 +483,17 @@ Future<void> forgetSpecificDevice(AuthDevice myDevice) async {
483
483
}
484
484
// #enddocregion forget-specific-device
485
485
486
+ // #docregion fetch-current-device
487
+ Future <void > fetchCurrentUserDevice () async {
488
+ try {
489
+ final device = await Amplify .Auth .fetchCurrentDevice ();
490
+ safePrint ('Device: $device ' );
491
+ } on AuthException catch (e) {
492
+ safePrint ('Fetch current device failed with error: $e ' );
493
+ }
494
+ }
495
+ // #enddocregion fetch-current-device
496
+
486
497
// #docregion fetch-devices
487
498
Future <void > fetchAllDevices () async {
488
499
try {
Original file line number Diff line number Diff line change @@ -1355,6 +1355,37 @@ class AuthCategory extends AmplifyCategory<AuthPluginInterface> {
1355
1355
() => defaultPlugin.rememberDevice (),
1356
1356
);
1357
1357
1358
+ /// {@template amplify_core.amplify_auth_category.fetch_current_device}
1359
+ /// Retrieves the current device.
1360
+ ///
1361
+ /// For more information about device tracking, see the
1362
+ /// [Amplify docs] (https://docs.amplify.aws/flutter/build-a-backend/auth/manage-users/manage-devices/#fetch-current-device).
1363
+ ///
1364
+ /// ## Examples
1365
+ ///
1366
+ /// <?code-excerpt "doc/lib/auth.dart" region="imports"?>
1367
+ /// ```dart
1368
+ /// import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
1369
+ /// import 'package:amplify_flutter/amplify_flutter.dart';
1370
+ /// ```
1371
+ ///
1372
+ /// <?code-excerpt "doc/lib/auth.dart" region="fetch-current-device"?>
1373
+ /// ```dart
1374
+ /// Future<AuthDevice> getCurrentUserDevice() async {
1375
+ /// try {
1376
+ /// final device = await Amplify.Auth.fetchCurrentDevice();
1377
+ /// safePrint('Device: $device');
1378
+ /// } on AuthException catch (e) {
1379
+ /// safePrint('Fetch current device failed with error: $e');
1380
+ /// }
1381
+ /// }
1382
+ /// ```
1383
+ /// {@endtemplate}
1384
+ Future <AuthDevice > fetchCurrentDevice () => identifyCall (
1385
+ AuthCategoryMethod .fetchCurrentDevice,
1386
+ () => defaultPlugin.fetchCurrentDevice (),
1387
+ );
1388
+
1358
1389
/// {@template amplify_core.amplify_auth_category.forget_device}
1359
1390
/// Forgets the current device.
1360
1391
///
Original file line number Diff line number Diff line change @@ -52,7 +52,8 @@ enum AuthCategoryMethod with AmplifyCategoryMethod {
52
52
setMfaPreference ('49' ),
53
53
getMfaPreference ('50' ),
54
54
setUpTotp ('51' ),
55
- verifyTotpSetup ('52' );
55
+ verifyTotpSetup ('52' ),
56
+ fetchCurrentDevice ('59' );
56
57
57
58
const AuthCategoryMethod (this .method);
58
59
Original file line number Diff line number Diff line change @@ -189,6 +189,11 @@ abstract class AuthPluginInterface extends AmplifyPluginInterface {
189
189
throw UnimplementedError ('forgetDevice() has not been implemented.' );
190
190
}
191
191
192
+ /// {@macro amplify_core.amplify_auth_category.fetch_current_device}
193
+ Future <AuthDevice > fetchCurrentDevice () {
194
+ throw UnimplementedError ('fetchCurrentDevice() has not been implemented.' );
195
+ }
196
+
192
197
/// {@macro amplify_core.amplify_auth_category.fetch_devices}
193
198
Future <List <AuthDevice >> fetchDevices () {
194
199
throw UnimplementedError ('fetchDevices() has not been implemented.' );
You can’t perform that action at this time.
0 commit comments