Replace updateCurrentAccount() with refreshSession() #3910
Merged
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.
Extracted-ish from #3728.
When you change
email
,handle
,emailConfirmed
, or other fields present in thesession
object, it would previously get updated in local state. However, the underlyingagent.session
was not updated. So there could be cases where anagent.session
would reflect back into the app state and clobber it (despite being out of date).Ideally the agent should take care of updating its own
agent.session
(and emitting anupdate
event) when we call API methods that are known to mutateemail
,handle
, etc. Until it does that, we're going to explicitly callagent.resumeSession
in those places to force a session refetch which will go through the usual mechanism. We don't need any special state handling because it'll be handled in our existing handler for theupdate
event.Since we don't need any special handling for the state, and because most likely this logic will later move into the agent itself anyway, I ripped
updateCurrentAccount
out of the session API interface.Test Plan
Changed email, verified email, changed handle, changed 2FA setting. Everything seems to be reflected in the UI.
These "feel" a bit slower (due to a serial request) but we should really fix that in the agent itself. I think it's OK. We can also add better pending states (e.g. disable the 2FA switch while toggling it), but I didn't do it in this PR.