I have a angular application with login page. We have set the max no.of retry attempts which is configurable. The login page is working as expected on success. The issue is on failure. The no.of retry attempts gets doubled for each single failed attempt. Ex: If the no. of retry attempts allowed is 6, the account gets locked while trying for the third time instead of allowing till 6 times.
I found out that the issue is due to the call that is happening twice on the failure of the login API. But there is no code written to call api twice from angular.
I had also debugged the code and found that the error block of the http client service is called only after the api completes the 2nd call.
So my question is why is this happening, why is the login API is called twice on failure (400 Bad Request) ?
Any help would be of great help.
Authentication service Code in angular:
authenticate(userName: string, password: string, authenticationType: string) {
let url = `${this.authenticationServiceURL}api/login`;
const un: string = userName;
let currentUser = new AuthenticatedUser();
currentUser.userName = userName;
const encryptedPassword = this.encryptionService.encrypt(password, environment.encryptionKey);
url += `?username=${un}`;
url += `&password=${encodeURIComponent(encryptedPassword)}`;
url += `&loginType=${authenticationType}`;
const obj = {};
return this.http.post(url, obj).pipe(
map((result: AccessToken) => {
if (result) {
if (result.access_token) {
currentUser = this.buildCurrentUserFromToken(result.access_token);
this.currentUser = currentUser;
sessionStorage.setItem('token', `${'Bearer '}${currentUser.token}`);
localStorage.setItem(LocalStorageNames.CURRENTUSER, JSON.stringify(this.currentUser));
return currentUser;
}
}
return of(null);
})
);
}
My bad, I had an error inteceptor which was handling the errors and replaying the request on error. That was the root cause for this issue. Modifying the interceptor fixed this issue. Thanks all for your responses especially @jeremyBenks for pointing me to the interceptors which I missed the error interceptor alone.