diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/AuthConfigureOperation.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/AuthConfigureOperation.swift index 49ca97e23a..376ffefc4c 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/AuthConfigureOperation.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/AuthConfigureOperation.swift @@ -37,6 +37,9 @@ class AuthConfigureOperation: ConfigureOperation { override public func main() { if isCancelled { finish() + dispatch(result: .failure(AuthError.configuration( + "Configuration operation was cancelled", + "", nil))) return } @@ -51,6 +54,7 @@ class AuthConfigureOperation: ConfigureOperation { for await state in stateSequences { if case .configured = state { finish() + dispatch(result: .success(())) break } } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ConfigurationTests/AWSCognitoAuthPluginConfigTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ConfigurationTests/AWSCognitoAuthPluginConfigTests.swift index 8ba574028e..553406fbe6 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ConfigurationTests/AWSCognitoAuthPluginConfigTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ConfigurationTests/AWSCognitoAuthPluginConfigTests.swift @@ -236,4 +236,45 @@ class AWSCognitoAuthPluginConfigTests: XCTestCase { } } + /// Test that the Auth plugin emits `InternalConfigureAuth` that is used by the Logging Category + /// + /// - Given: Given a valid config + /// - When: + /// - I configure auth with the given configuration + /// - Then: + /// - I should receive `InternalConfigureAuth` Hub event + /// + func testEmittingInternalConfigureAuthHubEvent() throws { + let expectation = expectation(description: "conifguration should complete") + let subscription = Amplify.Hub.publisher(for: .auth).sink { payload in + + if payload.eventName == "InternalConfigureAuth" { + expectation.fulfill() + } + } + let plugin = AWSCognitoAuthPlugin() + try Amplify.add(plugin: plugin) + + let categoryConfig = AuthCategoryConfiguration(plugins: [ + "awsCognitoAuthPlugin": [ + "CredentialsProvider": [ + "CognitoIdentity": [ + "Default": [ + "PoolId": "cc", + "Region": "us-east-1" + ] + ] + ] + ] + ]) + let amplifyConfig = AmplifyConfiguration(auth: categoryConfig) + do { + try Amplify.configure(amplifyConfig) + } catch { + XCTFail("Should not throw error. \(error)") + } + wait(for: [expectation], timeout: 5.0) + subscription.cancel() + } + } diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingCategoryClient.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingCategoryClient.swift index 9a0458f612..af7e1ace28 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingCategoryClient.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingCategoryClient.swift @@ -87,9 +87,10 @@ final class AWSCloudWatchLoggingCategoryClient { enum CognitoEventName: String { case signInAPI = "Auth.signInAPI" case signOutAPI = "Auth.signOutAPI" + case configured = "InternalConfigureAuth" } switch payload.eventName { - case HubPayload.EventName.Auth.signedIn, CognitoEventName.signInAPI.rawValue: + case HubPayload.EventName.Auth.signedIn, CognitoEventName.signInAPI.rawValue, CognitoEventName.configured.rawValue: takeUserIdentifierFromCurrentUser() case HubPayload.EventName.Auth.signedOut, CognitoEventName.signOutAPI.rawValue: self.userIdentifier = nil diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingPlugin.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingPlugin.swift index ba8721681f..0d15827c21 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingPlugin.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingPlugin.swift @@ -154,10 +154,6 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin { let localStore: LoggingConstraintsLocalStore = UserDefaults.standard localStore.reset() } - - DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) { - self.loggingClient.takeUserIdentifierFromCurrentUser() - } } }