witoldsz / angular-http-auth

MIT License
2.38k stars 418 forks source link

ignoreAuthModule: true makes httpBuffer empty #96

Closed deepikakamboj closed 9 years ago

deepikakamboj commented 9 years ago

I don't want the '/login' request to be fired again on loginConfirmed() but other requests in the buffer to be fired. So I used ignoreAuthModule: true in the login post. But this somehow makes buffer [] and so requests are made.

It works fine if login is successful the first time. But if I have provided wrong password, login returns 401, on reentering correct password, the other calls that should be made are not made.

$http({ignoreAuthModule: true, method: 'POST', url: '/s/login', data: loginData, headers: {'x-csrf-token': csrfToken}}) .success(function () { console.log('success case'); $scope.busy = false; angular.element('#loginModal').modal('hide'); authService.loginConfirmed(); }) .error(function (data, status) { console.log('error case'); $scope.busy = false; if (status === 401) { $scope.error = 'Incorrect username and/or password!'; } else { $scope.error = 'An error occurred: ' + (data || {}).reason; } authService.loginCancelled(); }); })

deepikakamboj commented 9 years ago

Understood the issue I was facing. The buffer was becoming empty because it first reached the error case and in loginCancelled(), the buffer is set to empty. Removed authService.loginCancelled() from my code in error scenario and it works fine now.

witoldsz commented 9 years ago

Hi, I am glad it all works for you. BTW: in the future, when you paste code snippets, use proper format tags, so the code is readable. See this:

$http({
  ignoreAuthModule: true, 
  method: 'POST', 
  url: '/s/login', 
  data: loginData, 
  headers: {'x-csrf-token': csrfToken}
})
.success(function () {
   console.log('success case');
   $scope.busy = false;
   angular.element('#loginModal').modal('hide');
   authService.loginConfirmed();
})
[...]