Skip to content
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

Feat (Auth): Interface Implementation for fetchCurrentDevice #5070

Merged
Merged
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
11 changes: 11 additions & 0 deletions packages/amplify_core/doc/lib/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,17 @@ Future<void> forgetSpecificDevice(AuthDevice myDevice) async {
}
// #enddocregion forget-specific-device

// #docregion fetch-current-device
Future<void> 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<void> fetchAllDevices() async {
try {
Expand Down
31 changes: 31 additions & 0 deletions packages/amplify_core/lib/src/category/amplify_auth_category.dart
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/flutter/build-a-backend/auth/manage-users/manage-devices/#fetch-current-device).
///
/// ## 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('Fetch 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
Loading