Fix various post sign out requests + bugs#1075
Conversation
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
| // make this request at all and clear the request queue | ||
| networkRequestQueue = []; | ||
| return; | ||
| } |
There was a problem hiding this comment.
If we don't do this we'll allow a request to be made that can't possibly succeed so it's better that we never make it at all.
There was a problem hiding this comment.
If someone adds another throw inside enhanceParameters, or there is some kind of bug that gets introduced that throws an unexpected error, it's not clear that this will cause the network queue to be cleared. I'd rather be very explicit about how this work by doing maybe one of these solutions:
- Have a method
Network.clearRequestQueue()that is called in place of thethrow new Error('A request was made without an authToken');. I'd prefer this one because it's very clear what the intention of the code is. - Have specific checking here on
errto only clear the request queue when theA request was made without an authTokenerror is thrown. I don't like this as much because if I were just looking ataddAuthTokenToParametersI wouldn't know that clearing the network queue could be a side-effect of throwing an error.
There was a problem hiding this comment.
Ok, that's a valid concern. The problem with 1 if that we probably don't need to make any request if we have no authToken. Clearing the network request queue alone doesn't achieve this since we are already making this request on the next line.
There was a problem hiding this comment.
Will think about this some more.
There was a problem hiding this comment.
Ok I got a better solution. We will:
- Clear and pause the request queue via
addAuthTokenToParameters() - Check to see if calling
enhanceParameters()paused the queue and return early
| // A report can be missing a name if a comment is received via pusher event | ||
| // and the report does not yet exist in Onyx (eg. a new DM created with the logged in person) | ||
| if (report.reportName === undefined) { | ||
| if (report.reportID && report.reportName === undefined) { |
There was a problem hiding this comment.
In some cases, report data will show up first without a reportID and no reportName. In those cases, we should not attempt to fetch a report that has no reportID
There was a problem hiding this comment.
Should we attempt to fetch data with ReportID but undefined reportName?
There was a problem hiding this comment.
Yeah so, it's completely OK to do that (see the comment above) and in fact we want to because we might be handling a report comment from Pusher and we need to download it. Reports that we've downloaded already should have some kind of report name in storage. This is a little weird but it's just how it works for now. Maybe in the future we will fix this to make it more obvious that a report has not been fetched from the server and won't use the reportName implementation detail.
There was a problem hiding this comment.
How would it be possible for there to be a report without a reportID? Especially since the Onyx key uses the report ID in the name of the key?
There was a problem hiding this comment.
In theory, this could happen anytime we call merge() for a report that doesn't exist without also including the reportID. I'm not exactly sure what situation leads to that happening here, but this seems like a safe way to avoid calling an API that is guaranteed to fail.
| // If we have an old login for some reason, we should delete it before storing the new details | ||
| if (credentials.login) { | ||
| API.DeleteLogin({ | ||
| authToken: authenticateResponse.authToken, |
There was a problem hiding this comment.
This seemed to be failing due to not having an authToken despite authenticating just prior.
There was a problem hiding this comment.
I think this should be avoided and I would rather dig into why the authToken sent with the DeleteLogin request is incorrect. Maybe this is what we are discussing in this slack thread today?
|
Ran out of time today, will have to review tomorrow morning. |
Gonals
left a comment
There was a problem hiding this comment.
Looks good, just one question!
|
@tgolen All yours! |
| // make this request at all and clear the request queue | ||
| networkRequestQueue = []; | ||
| return; | ||
| } |
There was a problem hiding this comment.
If someone adds another throw inside enhanceParameters, or there is some kind of bug that gets introduced that throws an unexpected error, it's not clear that this will cause the network queue to be cleared. I'd rather be very explicit about how this work by doing maybe one of these solutions:
- Have a method
Network.clearRequestQueue()that is called in place of thethrow new Error('A request was made without an authToken');. I'd prefer this one because it's very clear what the intention of the code is. - Have specific checking here on
errto only clear the request queue when theA request was made without an authTokenerror is thrown. I don't like this as much because if I were just looking ataddAuthTokenToParametersI wouldn't know that clearing the network queue could be a side-effect of throwing an error.
| // A report can be missing a name if a comment is received via pusher event | ||
| // and the report does not yet exist in Onyx (eg. a new DM created with the logged in person) | ||
| if (report.reportName === undefined) { | ||
| if (report.reportID && report.reportName === undefined) { |
There was a problem hiding this comment.
How would it be possible for there to be a report without a reportID? Especially since the Onyx key uses the report ID in the name of the key?
| // If we have an old login for some reason, we should delete it before storing the new details | ||
| if (credentials.login) { | ||
| API.DeleteLogin({ | ||
| authToken: authenticateResponse.authToken, |
There was a problem hiding this comment.
I think this should be avoided and I would rather dig into why the authToken sent with the DeleteLogin request is incorrect. Maybe this is what we are discussing in this slack thread today?
|
Updated this one. |
tgolen
left a comment
There was a problem hiding this comment.
Cool, I like how you solved that. It's a little awkward to see a double-check for the queue being paused, but the comment you added clarifies why it's necessary and I don't see any other way around it.
|
Updated |
@Julesssss @tgolen
Details
There are a few login bugs that I noticed while testing the sign in / sign out flows and I'm addressing them all here.
Fixed Issues
Fixes https://github.com/Expensify/Expensify/issues/148468
Tests
Screenshots
❌