Skip to content

(deprecated) Feat: Adding interfaces for fetchCurrentDevice API #5069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,37 @@ class AuthCategory extends AmplifyCategory<AuthPluginInterface> {
() => 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/lib/auth/device_features/q/platform/flutter/).
///
/// ## Examples
///
/// <?code-excerpt "doc/lib/auth.dart" region="imports"?>
/// ```dart
/// import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
/// import 'package:amplify_flutter/amplify_flutter.dart';
/// ```
///
/// <?code-excerpt "doc/lib/auth.dart" region="fetch-current-device"?>
/// ```dart
/// Future<AuthDevice> getCurrentUserDevice() async {
/// try {
/// final device = await Amplify.Auth.fetchCurrentDevice();
/// safePrint('Device: $device');
/// } on AuthException catch (e) {
/// safePrint('Get current device failed with error: $e');
/// }
/// }
/// ```
/// {@endtemplate}
Future<AuthDevice> fetchCurrentDevice() => identifyCall(
AuthCategoryMethod.fetchCurrentDevice,
() => defaultPlugin.fetchCurrentDevice(),
);

/// {@template amplify_core.amplify_auth_category.forget_device}
/// Forgets the current device.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ enum AuthCategoryMethod with AmplifyCategoryMethod {
setMfaPreference('49'),
getMfaPreference('50'),
setUpTotp('51'),
verifyTotpSetup('52');
verifyTotpSetup('52'),
fetchCurrentDevice('59');

const AuthCategoryMethod(this.method);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuthDevice> fetchCurrentDevice() {
throw UnimplementedError('fetchCurrentDevice() has not been implemented.');
}

/// {@macro amplify_core.amplify_auth_category.fetch_devices}
Future<List<AuthDevice>> fetchDevices() {
throw UnimplementedError('fetchDevices() has not been implemented.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ Future<List<AuthUserAttribute>> fetchUserAttributes() async {
return Amplify.Auth.fetchUserAttributes();
}

Future<AuthDevice> fetchCurrentDevice() async {
return Amplify.Auth.fetchCurrentDevice();
}

Future<List<AuthDevice>> fetchDevices() async {
return Amplify.Auth.fetchDevices();
}
Expand Down
Loading