This repository was archived by the owner on Mar 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Feature/sup 2663 #606
Merged
Merged
Feature/sup 2663 #606
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,12 @@ | |
|
||
angular.module('tc.services').factory('TcAuthService', TcAuthService); | ||
|
||
TcAuthService.$inject = ['CONSTANTS', 'auth', 'AuthTokenService', '$rootScope', '$q', '$log', '$timeout', 'UserService', 'Helpers', 'ApiService', 'store']; | ||
TcAuthService.$inject = ['CONSTANTS', 'auth', 'AuthTokenService', '$rootScope', '$q', '$log', '$timeout', 'UserService', 'Helpers', 'ApiService', 'store', '$http']; | ||
|
||
function TcAuthService(CONSTANTS, auth, AuthTokenService, $rootScope, $q, $log, $timeout, UserService, Helpers, ApiService, store) { | ||
function TcAuthService(CONSTANTS, auth, AuthTokenService, $rootScope, $q, $log, $timeout, UserService, Helpers, ApiService, store, $http) { | ||
$log = $log.getInstance("TcAuthServicetcAuth"); | ||
var auth0 = auth; | ||
var apiUrl = CONSTANTS.API_URL_V3; | ||
var service = { | ||
login: login, | ||
socialLogin: socialLogin, | ||
|
@@ -162,6 +163,19 @@ | |
} | ||
|
||
function logout() { | ||
$http({ | ||
url: apiUrl + '/authorizations/1', | ||
method: 'DELETE', | ||
headers: { | ||
'Authorization': "Bearer " + AuthTokenService.getV3Token() | ||
}, | ||
data: {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we can remove that line. On Thu, Dec 10, 2015 at 10:04 AM, Nicholas Litwin [email protected]
Thanks |
||
}).then(function(res) { | ||
$log.log('logout successful'); | ||
}).catch(function(resp) { | ||
$log.error('logout error'); | ||
}); | ||
|
||
return $q(function(resolve, reject) { | ||
AuthTokenService.removeTokens(); | ||
$rootScope.$broadcast(CONSTANTS.EVENT_USER_LOGGED_OUT); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?
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:
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 withAuthTokenService.removeTokens();
and$rootScope.$broadcast(CONSTANTS.EVENT_USER_LOGGED_OUT);
Maybe I'm just not seeing something