Skip to content

Commit

Permalink
Bugfix: defer 'change' events on sign out
Browse files Browse the repository at this point in the history
Wait for API calls to resolve before emitting `change` events on sign out. Otherwise, `change` is fired while we still have a signed-in session in Panoptes.
  • Loading branch information
eatyourgreens committed Jul 6, 2023
1 parent 65f0f54 commit b267b0b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,8 @@ const authClient = new Model({
console.log('Disabling account');
const user = await this.checkCurrent();
if (user) {
await user.delete();
this._deleteBearerToken();
this._currentUserPromise = Promise.resolve(null);
await this._currentUserPromise;
this._currentUserPromise = await user.delete().then(() => null);
this.emit('change', this._currentUserPromise);
console.info('Disabled account');
return null;
Expand All @@ -312,10 +310,9 @@ const authClient = new Model({
};

try {
makeCredentialHTTPRequest('DELETE', url, null, deleteHeaders);
this._deleteBearerToken();
this._currentUserPromise = Promise.resolve(null);
await this._currentUserPromise;
this._currentUserPromise = await makeCredentialHTTPRequest('DELETE', url, null, deleteHeaders)
.then(() => null);
this.emit('change', this._currentUserPromise);
console.info('Signed out');
return null;
Expand Down

0 comments on commit b267b0b

Please sign in to comment.