-
Notifications
You must be signed in to change notification settings - Fork 59
Conversation
headers: { | ||
'Authorization': "Bearer " + AuthTokenService.getV3Token() | ||
}, | ||
data: {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need data: {}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we can remove that line.
-P
On Thu, Dec 10, 2015 at 10:04 AM, Nicholas Litwin [email protected]
wrote:
In app/services/tcAuth.service.js
#606 (comment)
:@@ -162,6 +163,19 @@
}function logout() {
$http({
url: apiUrl + '/authorizations/1',
method: 'DELETE',
headers: {
'Authorization': "Bearer " + AuthTokenService.getV3Token()
},
data: {}
Do we need data: {}?
—
Reply to this email directly or view it on GitHub
https://github.com/appirio-tech/topcoder-app/pull/606/files#r47260868.
Thanks
Parth Shah
@@ -162,6 +163,18 @@ | |||
} | |||
|
|||
function logout() { | |||
$http({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will quite work. $http call is a promise so even before it's resolved AuthTokenService would be called. I think the solution is to chain these promises
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this work?
return $http({
...
}).then(function(res) {
AuthTokenService.removeTokens();
$rootScope.$broadcast(CONSTANTS.EVENT_USER_LOGGED_OUT);
}).catch(function(err) {
// handle error
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so :). As long we log exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should move more toward naming variables and passing them in. To me, this would be preferable:
function logout() {
var logoutOptions = {
url: apiUrl + '/authorizations/1',
method: 'DELETE',
headers: {
Authorization: 'Bearer ' + AuthTokenService.getV3Token()
}
};
var removeTokens = function() {
$log.log('Logout successful.');
AuthTokenService.removeTokens();
$rootScope.$broadcast(CONSTANTS.EVENT_USER_LOGGED_OUT);
};
// Name below according to what it does
var describesWhatHappensOnError = function(error) {
$log.error(error);
};
$http(logoutOptions)
.then(removeTokens)
.catch(describesWhatHappensOnError);
}
What do you guys think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parthshah @nlitwin -- the way I'm doing it now works. These don't need to be chained, since it's fine if the tokens get removed before the DELETE request goes through. I can do the logoutOptions
thing to make this cleaner, but I think it's fine to have these calls be independent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is indeed ok to remove the tokens before the DELETE
request is finished, do we need $q
? I think we might be able to get rid of $q
either way since there is nothing asynchronous to wait for with AuthTokenService.removeTokens();
and $rootScope.$broadcast(CONSTANTS.EVENT_USER_LOGGED_OUT);
Maybe I'm just not seeing something
fyi @nlitwin @parthshah @vikasrohit