Skip to content

Commit 35aea90

Browse files
author
Timothy E. Johansson
committed
Async logout
1 parent cd9aec3 commit 35aea90

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ Logged in users who try to access the route without the proper permissions will
237237

238238
## Loaders
239239

240-
All directives except `ua-logout` sets the scope variable `loading` to `true` while it's doing work in the background. This way you could show a loader animation while waiting for the UserApp API to respond. Here's an example with the login form:
240+
All directives sets the scope variable `loading` to `true` while it's doing work in the background. This way you could show a loader animation while waiting for the UserApp API to respond. Here's an example with the login form:
241241

242242
```html
243243
<form ua-login>

angularjs.userapp.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,15 @@ var userappModule = angular.module('UserApp', []);
390390
that.reset();
391391
});
392392
} else {*/
393-
UserApp.User.logout(function(error) {});
394-
that.reset();
393+
UserApp.User.logout(function(error) {
394+
that.reset();
395+
$rootScope.$broadcast('user.logout');
396+
callback && callback(error);
397+
});
395398
//}
396399

397-
$rootScope.$broadcast('user.logout');
398-
callback && callback(error);
400+
//$rootScope.$broadcast('user.logout');
401+
//callback && callback(error);
399402
},
400403

401404
// Send reset password email
@@ -530,13 +533,27 @@ var userappModule = angular.module('UserApp', []);
530533
});
531534

532535
// Logout directive
533-
userappModule.directive('uaLogout', function(user) {
536+
userappModule.directive('uaLogout', function($timeout, user) {
534537
return {
535538
restrict: 'A',
536539
link: function(scope, element, attrs) {
537540
var evHandler = function(e) {
538541
e.preventDefault();
539-
user.logout();
542+
543+
if (scope.loading) {
544+
return false;
545+
}
546+
547+
$timeout(function() {
548+
scope.loading = true;
549+
});
550+
551+
user.logout(function() {
552+
$timeout(function() {
553+
scope.loading = false;
554+
});
555+
});
556+
540557
return false;
541558
};
542559

0 commit comments

Comments
 (0)