Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: HealthKit Sample Upload Before Firebase Login #72

Open
1 task done
MarcSchlichting opened this issue Mar 6, 2024 · 5 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@MarcSchlichting
Copy link

Description

When closing the app entirely (not running in the background) and opening it again, some HK samples can get lost as they are never transferred to Firebase. From reading the log messages (error message: Could not store HealthKit Sample: Error Domain=Standard.StandardError Code = 0). I believe that this is due to the app trying to push data to Firebase before the app is authenticated with Firebase.

Reproduction

Closing the app entirely (in the simulator and a real device), not just pressing the home button (or the equivalent for the newer iPhones), creating a new HealthKit sample (e.g., manually adding it in the Health App) and then re-opening the template application causes the error. The error message can be seen when the console entries are logged or through observing the Firebase backend.

Expected behavior

The authentication should happen first and only after the app is correctly authenticated, a sample transfer should happen and no samples should be lost.

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct and Contributing Guidelines
@MarcSchlichting MarcSchlichting added the bug Something isn't working label Mar 6, 2024
@PSchmiedmayer
Copy link
Member

@Supereg We have resolved this in the TBI app by adding the Firebase configuration module as a dependency of the Standard and manually using the Firebase functions to obtain a cached user.

It would be good to explore how we might automate that setup that Spezi Firebase Auth code and Account injection somehow is guaranteed to run before a HealthKit data type could arrive?

@Supereg
Copy link
Member

Supereg commented Mar 6, 2024

So what you are doing in TBI is directly accessing Auth.auth().currentUser which is present from the start?

What we currently do in SpeziFirebase is to force refresh the auth token upon app startup. This code was kept from the original version of SpeziAccount/SpeziFirebase. We could choose to remove that altogether, which should improve configuration time of the SpeziFirebase module. I assume, Firebase would automatically refresh the token before you do the next request.

@PSchmiedmayer
Copy link
Member

Yes, that is the current approach we follow in TBI.

I think it is good to inject the account as early as possible. We can still do the token refresh once we already set the user as signed in and provided all the information right on the startup?

@Supereg
Copy link
Member

Supereg commented Mar 6, 2024

I'm not sure where the original rationale came from to refresh the token upon app start. I think it might make sense to keep that to e.g. have a smooth experience when there are external changes to your account.

But I agree, we should aim for getting the Account details ready faster (at least partially, e.g., it might take a while to load the user details from an external storage provider. Otherwise, we could choose to cache that on disk as well.)

@PSchmiedmayer
Copy link
Member

This issue is related to StanfordSpezi/SpeziFirebase#29; closing this issue should resolve this behavior in the Template App.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

3 participants