Skip to content

Commit f1adb97

Browse files
committed
add http interceptor & register will broadcast userSignIn event
1 parent 3b0dd3a commit f1adb97

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/config/satellizer.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,18 @@ angular.module('codexen')
55

66
$httpProvider.defaults.useXDomain = true
77
delete $httpProvider.defaults.headers.common['X-Requested-With']
8+
$httpProvider.interceptors.push(function ($q, $injector) {
9+
return {
10+
responseError: function (res) {
11+
switch (res.status) {
12+
case 401:
13+
var $state = $injector.get('$state')
14+
$state.go('auth.signin')
15+
break
16+
}
17+
18+
return $q.reject(res)
19+
}
20+
}
21+
})
822
})

src/controllers/states/AuthRegisterController.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global angular */
22
angular.module('codexen')
3-
.controller('AuthRegisterController', function ($auth, $log) {
3+
.controller('AuthRegisterController', function ($auth, $log, $state, $rootScope) {
44
var vm = this
55
vm.isEmpty = function (obj) {
66
for (var i in obj) if (obj.hasOwnProperty(i)) return false
@@ -13,7 +13,8 @@ angular.module('codexen')
1313
name: vm.name,
1414
profileName: vm.profileName
1515
}).then(function (data) {
16-
console.log(data)
16+
$rootScope.$broadcast('userSignIn')
17+
$state.go('home')
1718
})
1819
}
1920
})

0 commit comments

Comments
 (0)