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

cleanup promises #243

Merged
merged 1 commit into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 13 additions & 18 deletions addon/authenticators/jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,8 @@ export default TokenAuthenticator.extend({
otherwise
*/
authenticate(credentials, headers) {
return new Promise((resolve, reject) => {
this.makeRequest(this.serverTokenEndpoint, credentials, assign({}, this.headers, headers))
.then(response => this.handleAuthResponse(response.json))
.then(resolve, reject);
});
return this.makeRequest(this.serverTokenEndpoint, credentials, assign({}, this.headers, headers))
.then(response => this.handleAuthResponse(response.json));
},

/**
Expand Down Expand Up @@ -178,18 +175,16 @@ export default TokenAuthenticator.extend({
refreshAccessToken(token) {
const data = this.makeRefreshData(token);

return new Promise((resolve, reject) => {
this.makeRequest(this.serverTokenRefreshEndpoint, data, this.headers)
.then(response => {
const sessionData = this.handleAuthResponse(response.json);
this.trigger('sessionDataUpdated', sessionData);
resolve(sessionData);
})
.catch(error => {
this.handleTokenRefreshFail(error.status);
reject(error);
});
});
return this.makeRequest(this.serverTokenRefreshEndpoint, data, this.headers)
.then(response => {
const sessionData = this.handleAuthResponse(response.json);
this.trigger('sessionDataUpdated', sessionData);
return sessionData;
})
.catch(error => {
this.handleTokenRefreshFail(error.status);
return Promise.reject(error);
});
},

/**
Expand Down Expand Up @@ -244,7 +239,7 @@ export default TokenAuthenticator.extend({
delete this._refreshTokenTimeout;
cancel(this._tokenExpirationTimeout);
delete this._tokenExpirationTimeout;
return new resolve();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this doesn't need new, it already returns new instance of Promise

return resolve();
},

/**
Expand Down
11 changes: 3 additions & 8 deletions addon/authenticators/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,8 @@ export default Base.extend({
@return {Promise} A promise that resolves when an auth token is successfully acquired from the server and rejects otherwise
*/
authenticate(credentials, headers) {
return new Promise((resolve, reject) => {
this.makeRequest(this.serverTokenEndpoint, credentials, assign({}, this.headers, headers)).then(response => {
return resolve(response.json);
}).catch(error => {
return reject(error);
});
});
return this.makeRequest(this.serverTokenEndpoint, credentials, assign({}, this.headers, headers))
.then(response => response.json);
},

/**
Expand All @@ -82,7 +77,7 @@ export default Base.extend({
@return {Promise} A resolving promise
*/
invalidate() {
return new resolve();
return resolve();
},

/**
Expand Down