66//
77
88import Amplify
9+ #if COCOAPODS
10+ import AWSMobileClient
11+ #else
12+ import AWSMobileClientXCF
13+ #endif
914
1015struct AuthDeviceServiceAdapter : AuthDeviceServiceBehavior {
1116
@@ -19,8 +24,7 @@ struct AuthDeviceServiceAdapter: AuthDeviceServiceBehavior {
1924 completionHandler: @escaping ( Result < [ AuthDevice ] , AuthError > ) -> Void ) {
2025
2126 awsMobileClient. listDevices { result, error in
22- if let error = error {
23- let authError = AuthErrorHelper . toAuthError ( error)
27+ if let authError = mapToAuthError ( error) {
2428 completionHandler ( . failure( authError) )
2529 return
2630 }
@@ -42,8 +46,7 @@ struct AuthDeviceServiceAdapter: AuthDeviceServiceBehavior {
4246
4347 guard let device = request. device else {
4448 awsMobileClient. forgetCurrentDevice { error in
45- if let error = error {
46- let authError = AuthErrorHelper . toAuthError ( error)
49+ if let authError = mapToAuthError ( error) {
4750 completionHandler ( . failure( authError) )
4851 return
4952 }
@@ -52,8 +55,7 @@ struct AuthDeviceServiceAdapter: AuthDeviceServiceBehavior {
5255 return
5356 }
5457 awsMobileClient. forgetDevice ( deviceId: device. id) { error in
55- if let error = error {
56- let authError = AuthErrorHelper . toAuthError ( error)
58+ if let authError = mapToAuthError ( error) {
5759 completionHandler ( . failure( authError) )
5860 return
5961 }
@@ -66,12 +68,29 @@ struct AuthDeviceServiceAdapter: AuthDeviceServiceBehavior {
6668 func rememberDevice( request: AuthRememberDeviceRequest ,
6769 completionHandler: @escaping ( Result < Void , AuthError > ) -> Void ) {
6870 awsMobileClient. updateDeviceStatus ( remembered: true ) { _, error in
69- if let error = error {
70- let authError = AuthErrorHelper . toAuthError ( error)
71+ if let authError = mapToAuthError ( error) {
7172 completionHandler ( . failure( authError) )
7273 return
7374 }
7475 completionHandler ( . success( ( ) ) )
7576 }
7677 }
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+ }
7796}
0 commit comments