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

Use new API command LogOut #9602

Merged
merged 14 commits into from
Jul 8, 2022
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import * as ValidationUtils from '../../ValidationUtils';
import * as Authentication from '../../Authentication';
import * as ErrorUtils from '../../ErrorUtils';
import * as Welcome from '../Welcome';
import * as API from '../../API';
import * as NetworkStore from '../../Network/NetworkStore';

let credentials = {};
Onyx.connect({
Expand Down Expand Up @@ -72,25 +74,34 @@ function createAccount(login) {
*/
function signOut() {
Log.info('Flushing logs before signing out', true, {}, true);
Timing.clearData();

if (credentials && credentials.autoGeneratedLogin) {
// Clean up the login that we created
DeprecatedAPI.DeleteLogin({
const optimisticData = [
{
onyxMethod: 'set',
key: ONYXKEYS.SESSION,
value: null,
},
{
onyxMethod: 'set',
key: ONYXKEYS.CREDENTIALS,
value: null,
},
];
API.write('LogOut', {
// Send current authToken because we will immediately clear it once triggering this command
authToken: NetworkStore.getAuthToken(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB, maybe kind of rare that this would happen - but feels like something that API should deal with by caching the authToken before setting optimisticData.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely think it's rare, but it's necessary for this case (took me a while to debug & figure out this was the cause of some annoying issues)

I like the idea of the API caching the authToken before setting optimisticData, but maybe only if there's other instances where that's needed? Like in other Authenticate refactors 'n such.

partnerUserID: credentials.autoGeneratedLogin,
partnerName: CONFIG.EXPENSIFY.PARTNER_NAME,
partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD,
shouldRetry: false,
})
.then((response) => {
if (response.jsonCode === CONST.JSON_CODE.SUCCESS) {
return;
}

Onyx.merge(ONYXKEYS.SESSION, {error: response.message});
});
}, {optimisticData});
return;
}

Onyx.set(ONYXKEYS.SESSION, null);
Onyx.set(ONYXKEYS.CREDENTIALS, null);
Timing.clearData();
}

function signOutAndRedirectToSignIn() {
Expand Down