Skip to content

Commit

Permalink
Auth module: explicitly emit 'change' events (#211)
Browse files Browse the repository at this point in the history
- Replace `this.update` with `this.emit` throughout the `auth` module.
  • Loading branch information
eatyourgreens committed Jul 3, 2023
1 parent d4911f8 commit 906c550
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,8 @@ const authClient = new Model({
};

const registrationRequest = this._makeRegistrationRequest(data);
this.update({
_currentUserPromise: registrationRequest.catch(function() {
return null;
}),
});
this._currentUserPromise = registrationRequest.catch(() => null);
this.emit('change', this._currentUserPromise);

return registrationRequest;
}
Expand All @@ -171,9 +168,8 @@ const authClient = new Model({
async checkCurrent() {
if (!this._currentUserPromise) {
console.log('Checking current user');
this.update({
_currentUserPromise: this._getUser()
});
this._currentUserPromise = this._getUser();
this.emit('change', this._currentUserPromise);
}

return this._currentUserPromise;
Expand Down Expand Up @@ -221,11 +217,8 @@ const authClient = new Model({
};

const signInRequest = this._makeSignInRequest(data);
this.update({
_currentUserPromise: signInRequest.catch(function() {
return null;
}),
});
this._currentUserPromise = signInRequest.catch(() => null);
this.emit('change', this._currentUserPromise);

return signInRequest;
}
Expand Down Expand Up @@ -291,9 +284,8 @@ const authClient = new Model({
if (user) {
await user.delete();
this._deleteBearerToken();
this.update({
_currentUserPromise: Promise.resolve(null),
});
this._currentUserPromise = Promise.resolve(null);
this.emit('change', this._currentUserPromise);
console.info('Disabled account');
return null;
} else {
Expand All @@ -318,9 +310,8 @@ const authClient = new Model({
try {
makeCredentialHTTPRequest('DELETE', url, null, deleteHeaders);
this._deleteBearerToken();
this.update({
_currentUserPromise: Promise.resolve(null),
});
this._currentUserPromise = Promise.resolve(null);
this.emit('change', this._currentUserPromise);
console.info('Signed out');
return null;
} catch (error) {
Expand Down

0 comments on commit 906c550

Please sign in to comment.