6
6
//
7
7
8
8
import Amplify
9
+ #if COCOAPODS
10
+ import AWSMobileClient
11
+ #else
12
+ import AWSMobileClientXCF
13
+ #endif
9
14
10
15
struct AuthDeviceServiceAdapter : AuthDeviceServiceBehavior {
11
16
@@ -19,8 +24,7 @@ struct AuthDeviceServiceAdapter: AuthDeviceServiceBehavior {
19
24
completionHandler: @escaping ( Result < [ AuthDevice ] , AuthError > ) -> Void ) {
20
25
21
26
awsMobileClient. listDevices { result, error in
22
- if let error = error {
23
- let authError = AuthErrorHelper . toAuthError ( error)
27
+ if let authError = mapToAuthError ( error) {
24
28
completionHandler ( . failure( authError) )
25
29
return
26
30
}
@@ -42,8 +46,7 @@ struct AuthDeviceServiceAdapter: AuthDeviceServiceBehavior {
42
46
43
47
guard let device = request. device else {
44
48
awsMobileClient. forgetCurrentDevice { error in
45
- if let error = error {
46
- let authError = AuthErrorHelper . toAuthError ( error)
49
+ if let authError = mapToAuthError ( error) {
47
50
completionHandler ( . failure( authError) )
48
51
return
49
52
}
@@ -52,8 +55,7 @@ struct AuthDeviceServiceAdapter: AuthDeviceServiceBehavior {
52
55
return
53
56
}
54
57
awsMobileClient. forgetDevice ( deviceId: device. id) { error in
55
- if let error = error {
56
- let authError = AuthErrorHelper . toAuthError ( error)
58
+ if let authError = mapToAuthError ( error) {
57
59
completionHandler ( . failure( authError) )
58
60
return
59
61
}
@@ -66,12 +68,29 @@ struct AuthDeviceServiceAdapter: AuthDeviceServiceBehavior {
66
68
func rememberDevice( request: AuthRememberDeviceRequest ,
67
69
completionHandler: @escaping ( Result < Void , AuthError > ) -> Void ) {
68
70
awsMobileClient. updateDeviceStatus ( remembered: true ) { _, error in
69
- if let error = error {
70
- let authError = AuthErrorHelper . toAuthError ( error)
71
+ if let authError = mapToAuthError ( error) {
71
72
completionHandler ( . failure( authError) )
72
73
return
73
74
}
74
75
completionHandler ( . success( ( ) ) )
75
76
}
76
77
}
78
+
79
+ private func mapToAuthError( _ error: Error ? ) -> AuthError ? {
80
+ guard let error = error else {
81
+ return nil
82
+ }
83
+
84
+ // `.notSignedIn` should be handled explicitly and not as part of AuthErrorHelper
85
+ if let awsMobileClientError = error as? AWSMobileClientError ,
86
+ case . notSignedIn = awsMobileClientError {
87
+ return AuthError . signedOut (
88
+ AuthPluginErrorConstants . userSignedOutError. errorDescription,
89
+ AuthPluginErrorConstants . userSignedOutError. recoverySuggestion,
90
+ error
91
+ )
92
+ } else {
93
+ return AuthErrorHelper . toAuthError ( error)
94
+ }
95
+ }
77
96
}
0 commit comments