Reactively tracking, if initial user has finished loading #159
bratelefant
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have an idea and actually a requirement that I'd like to address here regarding the log in flow of my offline-first rn app.
My general requirement is, that I want to present the user data as fast as possible after opening the app (on iOS: no matter if the app is resumed from "in ram" background or gets initially bootet up).
Until now I had to deal with the following flaw: Given the user was logged in before,
Meteor.connect
establishes the websocket connection, loads all subs and logs in the user with a resume token. Before the initial user was loaded, the users sub adds anull
user value forMeteor.user()
(quite logical, because whenloginWithToken
is not called / not finished, there should be no user). Then, after login, a non-null value ofMeteor.user()
gets send over the wire.Now the problem is, that if you want to have
Meteor.user()
to be fully reactive and use the value ofMeteor.user()
for navigation stuff (say, navigate the user to a Login screen, if it has a nullish value, usinguseEffect
), this always would result in navigating back and forth to the Login screen, and then to your "main" screen.In my branch fix/handle-token-login-callback I come up with a solution to this by simply adding a reactive function
Meteor.userReady()
that is set to false when the app is started, and set to true, when the login process has ended. (UsingMeteor.loggingIn()
will not help, since that value is falsish when you first start up your app.)Is this something to maybe add to the main branch?
And also in that branch I have added an option
options.AsyncTokenStorage
that can be used to specify a different store (expo secure store for example) to store the resume token in a different place than theLocal.Collection
data from the companion package (cf #154)Beta Was this translation helpful? Give feedback.
All reactions