only fail awaiting token confirmation for valid auth response #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug
An authenticated user is suddenly kicked to the unauthenticated view. This happens often when a native app is brought from background after token has expired, but can happen outside of this context as well.
Root cause
waitingForServerConfirmationOfFreshToken
.Transition
message showing the server has validated the token, or anAuthError
.AuthError
(source links below).Despite the user having a valid session and token, the client remains unauthenticated until refresh/reopen of app.
This solution
While authentication errors have the same type as expired token responses, the messages are currently distinct.
Error when ModifyQuerySet, Mutation, or Action message encounters an expired token:
https://github.com/get-convex/convex-backend/blob/4121cc0700cf47a16f0861655f1906d810085fba/crates/sync/src/state.rs#L271
Error when an Authenticate message encounters an expired token:
https://github.com/get-convex/convex-backend/blob/4121cc0700cf47a16f0861655f1906d810085fba/crates/authentication/src/lib.rs#L121
This solution is brittle, but fixes the problem until a more permanent fix can be applied. When the auth state is set to
waitingForServerConfirmationOfFreshToken
, only the auth error resulting from an Authenticate request can trigger clearing of auth state in the client. This is done by ignoring query/mutation/action auth errors via message text matching (again, brittle).Other solutions considered
An ideal solution would work similarly, but involve more distinct backend handling of these two error states, maybe through an explicit
AuthError
type alternative for Authenticate failures.