diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c54739..a4d5898 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 1.1.4 (2024-06-07) + +### Bug Fixes +- **Authenticator**: Showing the proper message when there's connectivity issues (#82) + +### Misc. Updates +- Updating code to support Amplify 2.35+. (#82) + ## 1.1.3 (2024-06-04) ### Bug Fixes diff --git a/Package.resolved b/Package.resolved index ef1d276..22cb682 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/aws-amplify/amplify-swift", "state" : { - "revision" : "0e4dc695c4cd3c53d145b9f6498ad83004edae6d", - "version" : "2.34.4" + "revision" : "fa6ca64f42c3e4e72cf6b62c30bc45b2be7b05bc", + "version" : "2.35.1" } }, { diff --git a/Package.swift b/Package.swift index 808c348..aeabb9f 100644 --- a/Package.swift +++ b/Package.swift @@ -13,7 +13,7 @@ let package = Package( targets: ["Authenticator"]), ], dependencies: [ - .package(url: "https://github.com/aws-amplify/amplify-swift", "2.16.0"..<"2.35.0"), + .package(url: "https://github.com/aws-amplify/amplify-swift", from: "2.35.0"), ], targets: [ .target( diff --git a/Sources/Authenticator/Models/AuthenticatorState.swift b/Sources/Authenticator/Models/AuthenticatorState.swift index 690a21b..e2899ec 100644 --- a/Sources/Authenticator/Models/AuthenticatorState.swift +++ b/Sources/Authenticator/Models/AuthenticatorState.swift @@ -7,7 +7,7 @@ import Amplify @_spi(InternalAmplifyPluginExtension) import AWSCognitoAuthPlugin -@_spi(InternalAmplifyPluginExtension) import AWSPluginsCore +@_spi(InternalAmplifyPluginExtension) import InternalAmplifyCredentials import Foundation /// An `ObservableObject` that represents the Authenticator's state diff --git a/Sources/Authenticator/States/AuthenticatorBaseState.swift b/Sources/Authenticator/States/AuthenticatorBaseState.swift index e985f30..32f82d1 100644 --- a/Sources/Authenticator/States/AuthenticatorBaseState.swift +++ b/Sources/Authenticator/States/AuthenticatorBaseState.swift @@ -213,6 +213,12 @@ public class AuthenticatorBaseState: ObservableObject { } } + // First check if the underlying error is a connectivity one + if isConnectivityError(error.underlyingError) { + log.verbose("The error is identified as a connectivity issue, displaying the corresponding localized string.") + return "authenticator.cognitoError.network".localized() + } + guard let cognitoError = error.underlyingError as? AWSCognitoAuthError else { log.verbose("Unable to localize error that is not of type AWSCognitoAuthError") return nil @@ -229,6 +235,20 @@ public class AuthenticatorBaseState: ObservableObject { log.verbose("No localizable string was found for error of type '\(cognitoError)'") return nil } + + private func isConnectivityError(_ error: Error?) -> Bool { + guard let error = error as? NSError else { + return false + } + let networkErrorCodes = [ + NSURLErrorCannotFindHost, + NSURLErrorCannotConnectToHost, + NSURLErrorNetworkConnectionLost, + NSURLErrorDNSLookupFailed, + NSURLErrorNotConnectedToInternet + ] + return networkErrorCodes.contains(where: { $0 == error.code }) + } } extension AuthenticatorBaseState: Equatable {