Skip to content
This repository was archived by the owner on Oct 5, 2020. It is now read-only.

Commit 0c33c2f

Browse files
authored
Merge pull request #485 from patrickmcelwee/480-fix-getUser
getAuthenticatedStatus needs to always return promise
2 parents 59057f0 + c5782cf commit 0c33c2f

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

app/templates/ui/app/login/login.service.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
function getAuthenticatedStatus() {
4040
if (_isAuthenticated !== undefined) {
41-
return _isAuthenticated;
41+
return $q.resolve(_isAuthenticated);
4242
}
4343

4444
return $http.get('/api/user/status', {}).then(function(response) {
@@ -120,6 +120,8 @@
120120
'params': JSON.stringify((_toStateParams || $stateParams))
121121
}).then(function() {
122122
d.reject();
123+
}, function(error) {
124+
throw error;
123125
});
124126
}
125127
return d.promise;
@@ -173,21 +175,12 @@
173175
}
174176

175177
if (routeIsProtected(next.name)) {
176-
var auth = service.getAuthenticatedStatus();
177-
178-
if (angular.isFunction(auth.then)) {
179-
auth.then(function() {
180-
if (!service.isAuthenticated()) {
181-
//this does NOT block requests in a timely fashion...
182-
blockRoute(event, next, nextParams);
183-
}
184-
});
185-
}
186-
else {
187-
if (!auth) {
178+
service.getAuthenticatedStatus().then(function() {
179+
if (!service.isAuthenticated()) {
180+
//this does NOT block requests in a timely fashion...
188181
blockRoute(event, next, nextParams);
189182
}
190-
}
183+
});
191184

192185
}
193186
});

app/templates/ui/app/user/user.service.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
angular.module('app.user')
55
.factory('userService', UserService);
66

7-
UserService.$inject = ['$rootScope', 'loginService'];
8-
function UserService($rootScope, loginService) {
7+
UserService.$inject = ['$rootScope', '$q', 'loginService'];
8+
function UserService($rootScope, $q, loginService) {
99
var _currentUser = null;
1010

1111
function currentUser() {
@@ -14,7 +14,7 @@
1414

1515
function getUser() {
1616
if (_currentUser) {
17-
return _currentUser;
17+
return $q.resolve(_currentUser);
1818
}
1919

2020
return loginService.getAuthenticatedStatus().then(currentUser);

0 commit comments

Comments
 (0)