witoldsz / angular-http-auth

MIT License
2.38k stars 417 forks source link

How to handle failed login #33

Closed tschofen closed 11 years ago

tschofen commented 11 years ago

When my login fails, the 401 errors get added to the httpBuffer. Thus, the login doesn't go away after success.

Looking through the source and the comments, I realize that this module looks for response.config.ignoreAuthModule when checking to add it to the httpBuffer, but wasn't not sure where to add it.

After some trial and error, here's an example of how this can be done:

        login: function(username, password) {
            var promise = $http({
                method: 'POST',
                url: CONFIG.BASEURL+'login',
                data: 'uname=' + username + '&pwd=' + password,
                headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                ignoreAuthModule: true
                })
                .then(function(response) {
                    ...
                    authService.loginConfirmed();
                });
            return promise;
        }

Hope that helps somebody else.