Describe the bug
When an existing user logs back in (signIn) the dataStore doesn't emit the ready
as per handling waiting as: Amplify.Hub.listen(to: .dataStore)
To Reproduce
Steps to reproduce the behavior:
Amplify.configureAmplify.Auth.signIn Amplify.HUB.listenready is called Expected behaviour
I expect the HubPayload.EventName.DataStore.ready aka "DataStore.ready" to be emitted by the HUB after all data gets pulled into the device for that user to kindly update UI.
As docs states here
Environment(please complete the following information):
Device Information (please complete the following information):
Additional context
readyreadysignOut on Cognito and Amplify.DataStore.clear in order to log back inThank you
Any help is really appreciated 馃憤
I've also tried uninstalling before to make sure the clear step wan't interfering but the result is the same
Also I've made a not-so-good workaround where right after I listen the HUB events, I call:
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
Amplify.DataStore.stop { result in
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
Amplify.DataStore.start {
print("-> started \($0)")
}
}
}
}
so that after the sync, it reloads all events from the API (way faster) and finally the ready is emitted.
I'm looking forward to delete that. 馃槄
This may be related to orphaned items. I've described that here. You may want to check if you have items where the parent is missing.
Also I've made a not-so-good workaround where right after I
listenthe HUB events, I call:DispatchQueue.main.asyncAfter(deadline: .now() + 2) { Amplify.DataStore.stop { result in DispatchQueue.main.asyncAfter(deadline: .now() + 2) { Amplify.DataStore.start { print("-> started \($0)") } } } }so that after the sync, it reloads all events from the API (way faster) and finally the
readyis emitted.
I'm looking forward to delete that. 馃槄
I believe I noticed a similar issue when I was trying to do this, I couldn't call start from the completion of the stop, because stop's completion actually hasn't completely finished stopping the sync engine. documented my findings over here: https://github.com/aws-amplify/amplify-ios/issues/1177 what you've done here is the workaround until we fix the stop then start issue
@dsaliberti could you provide us some details as to
@auth directive, type of connections between models, etc.DataStore.clear? is it when the user signs out? If so, you can call DataStore.start when the user signs back in, does this not work for you such that the ready event does not fire? Do you see any error logs with Amplify.Logging.logLevel = .verbose enabled?what type of models do you have in your schema? i鈥檇 like to understand how you鈥檙e annotating the models, ie. with @auth directive, type of connections between models, etc.
We use only simple models without any other annotation than @auth - no relation between objects
what auth type are you using for the API?
we use Cognito authentication via Amplify Plugin
can you clarify when you are calling DataStore.clear
sure, as soon as the user signOut with success, we call clear.
Amplify.Auth.signOut(...
switch result {
case .success:
...
Amplify.DataStore.clear { result in
but don't call start after wise. Only when an authentication happens, and "home" screen is loaded, we call start again.
I think we could try that now.
There is a log I see for a while now and I think it is relevant:
handleDataEvent(response:): ignoring data event for 2AEBD7A9-4AB7-44FB-93E1-DF5CCD531FAE
and I can see it's from
extension AppSyncSubscriptionConnection / func handleDataEvent(response: AppSyncResponse)
I hope it helps