@@ -31,6 +31,7 @@ import 'package:amplify_auth_cognito_dart/src/sdk/cognito_identity_provider.dart
31
31
ForgotPasswordRequest,
32
32
GetUserAttributeVerificationCodeRequest,
33
33
GetUserRequest,
34
+ GetDeviceRequest,
34
35
ListDevicesRequest,
35
36
ResendConfirmationCodeRequest,
36
37
UserContextDataType,
@@ -39,6 +40,7 @@ import 'package:amplify_auth_cognito_dart/src/sdk/cognito_identity_provider.dart
39
40
VerifyUserAttributeRequest;
40
41
import 'package:amplify_auth_cognito_dart/src/sdk/sdk_bridge.dart' ;
41
42
import 'package:amplify_auth_cognito_dart/src/sdk/src/cognito_identity_provider/model/analytics_metadata_type.dart' ;
43
+ import 'package:amplify_auth_cognito_dart/src/sdk/src/cognito_identity_provider/model/get_device_response.dart' ;
42
44
import 'package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart' ;
43
45
import 'package:amplify_auth_cognito_dart/src/state/state.dart' ;
44
46
import 'package:amplify_auth_cognito_dart/src/util/cognito_iam_auth_provider.dart' ;
@@ -97,6 +99,7 @@ class AmplifyAuthCognitoDart extends AuthPluginInterface
97
99
late CognitoAuthStateMachine _stateMachine = CognitoAuthStateMachine (
98
100
dependencyManager: dependencies,
99
101
);
102
+
100
103
StreamSubscription <AuthState >? _stateMachineSubscription;
101
104
102
105
/// The underlying state machine, for use in subclasses.
@@ -993,6 +996,46 @@ class AmplifyAuthCognitoDart extends AuthPluginInterface
993
996
.result;
994
997
}
995
998
999
+ @override
1000
+ Future <CognitoDevice > fetchCurrentDevice () async {
1001
+ final tokens = await stateMachine.getUserPoolTokens ();
1002
+ final deviceSecrets = await _deviceRepo.get (tokens.username);
1003
+ final deviceKey = deviceSecrets? .deviceKey;
1004
+ if (deviceSecrets == null || deviceKey == null ) {
1005
+ throw const DeviceNotTrackedException ();
1006
+ }
1007
+
1008
+ late GetDeviceResponse response;
1009
+
1010
+ try {
1011
+ response = await _cognitoIdp
1012
+ .getDevice (
1013
+ cognito.GetDeviceRequest (
1014
+ deviceKey: deviceKey,
1015
+ accessToken: tokens.accessToken.raw,
1016
+ ),
1017
+ )
1018
+ .result;
1019
+ } on Exception catch (error) {
1020
+ throw AuthException .fromException (error);
1021
+ }
1022
+
1023
+ final device = response.device;
1024
+ final attributes =
1025
+ device.deviceAttributes ?? const < cognito.AttributeType > [];
1026
+
1027
+ return CognitoDevice (
1028
+ id: deviceKey,
1029
+ attributes: {
1030
+ for (final attribute in attributes)
1031
+ attribute.name: attribute.value ?? '' ,
1032
+ },
1033
+ createdDate: device.deviceCreateDate,
1034
+ lastAuthenticatedDate: device.deviceLastAuthenticatedDate,
1035
+ lastModifiedDate: device.deviceLastModifiedDate,
1036
+ );
1037
+ }
1038
+
996
1039
@override
997
1040
Future <List <CognitoDevice >> fetchDevices () async {
998
1041
final allDevices = < CognitoDevice > [];
0 commit comments