amplify-swift icon indicating copy to clipboard operation
amplify-swift copied to clipboard

Hub.publisher does not receive all events

Open Robuske opened this issue 7 months ago • 4 comments
trafficstars

Describe the bug

The Hub.publisher(for:) does not receive all events that Hub.listen(to:) receives.

From what I have observed events like Amplify.configured, Auth.signedIn and Auth.signedOut are not received by the publisher (probably more). Important to note that it does receive the internal events like InternalConfigureAuth, Auth.signInAPI and Auth.signOutAPI.

From my (brief) investigation of the library I believe some places are calling the HubCategory.dispatch, which sends to the publisher and the plugin, while others are calling the HubCategoryPlugin.dispatch directly.

Steps To Reproduce

1. Configure a `Amplify.Hub.listen(to: .auth)` and a `Amplify.Hub.publisher(for: .auth)`
2. Configure `Amplify` with the plugin `AWSCognitoAuthPlugin`
3. Sign in
4. Sign out
5. Observe the difference in the events between the `listener` and the `publisher`.

Expected behavior

The listener and the publisher should receive the same events.

Amplify Framework Version

2.46.1

Amplify Categories

Auth

Dependency manager

Swift PM

Swift version

6.1

CLI version

Not using

Xcode version

16.3 (16E140)

Relevant log output

<details>
<summary>Log Messages</summary>


INSERT LOG MESSAGES HERE

</details>

Is this a regression?

No

Regression additional context

No response

Platforms

iOS

OS Version

18.4

Device

Any

Specific to simulators

No response

Additional context

No response

Robuske avatar Apr 17 '25 01:04 Robuske

@Robuske Thanks for opening the issue. I will look into the issue and get back to you.

harsh62 avatar Apr 17 '25 14:04 harsh62

@Robuske I started looking into the issue and found that the only event missing from publisher is Amplify.configured. I tested others and seems to be working fine.

<test> Listener received: Amplify.configured -- (missing in publisher)

<test> Publisher received: InternalConfigureAuth
<test> Listener received: InternalConfigureAuth

<test> Publisher received: Auth.fetchSessionAPI
<test> Listener received: Auth.fetchSessionAPI

<test> Publisher received: Auth.signInAPI
<test> Publisher received: Auth.signedIn

<test> Listener received: Auth.signInAPI
<test> Listener received: Auth.signedIn

<test> Publisher received: Auth.signOutAPI
<test> Publisher received: Auth.signedOut

<test> Listener received: Auth.signOutAPI
<test> Listener received: Auth.signedOut

Would you be able to provide more details on how you are using the publisher. I followed the Amplify docs: https://docs.amplify.aws/gen1/swift/build-a-backend/utilities/hub/ .

For the missing event, I will work on a fixing it.

harsh62 avatar May 13 '25 02:05 harsh62

@harsh62 I ended up using an implementation that does not rely on it, so I don't remember the details anymore.

But if your tests show that the values are being received, it should be enough.

Robuske avatar May 13 '25 18:05 Robuske

Thank you for replying. I'll keep the issue opened for one event that is not being fired.

harsh62 avatar May 13 '25 18:05 harsh62