Skip to content

Commit a2b20ea

Browse files
committedSep 4, 2019
refactor external controller
1 parent 1bc367e commit a2b20ea

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed
 

‎public/js/controllers/externalCtrl.js

+5-25
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,14 @@
1313
$scope.modalRegister = stateService.get('modalRegister');
1414
});
1515

16-
//this execute after every page refresh
1716
$localForage.getItem('authorization')
18-
.then(function (authData) {
19-
if (authData) {
20-
$scope.auth = true;
21-
} else {
22-
$scope.auth = false;
23-
}
24-
}, function () {
25-
console.log("error with getting authorization localForage after refresh");
26-
}
27-
);
17+
.then((authData) => { $scope.auth = authData });
2818

29-
//this execute after custom event emitted after success login response
30-
$rootScope.$on('authChange', function (event) {
19+
$rootScope.$on('user::auth', () => {
3120
$localForage.getItem('authorization')
32-
.then(function (authData) {
33-
if (authData) {
34-
$scope.auth = true;
35-
console.log('logged');
36-
} else {
37-
$scope.auth = false;
38-
$location.path('/');
39-
}
40-
}, function () {
41-
console.log("error with getting authorization localForage on event");
42-
}
43-
);
21+
.then((authData) => {
22+
$scope.auth = authData;
23+
});
4424
});
4525
}
4626

0 commit comments

Comments
 (0)
Please sign in to comment.