Currently using the Cognito Javascript SDK, I'm a bit surprised to be warned when the username I'm sending exists or not:
Here is the code I'm using:
login(username, password) {
const authenticationData = {
Username : username,
Password : password,
};
const authenticationDetails = new AuthenticationDetails(authenticationData);
const userPool = new CognitoUserPool(this.poolData);
const userData = {
Username : username,
Pool : userPool,
};
this.cognitoUser = new CognitoUser(userData);
this.cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log(result);
},
newPasswordRequired: function(...) {
},
onFailure: function(err) {
console.log(err);
},
});
}
If I set username
to mytest
(existing user) with a wrong password, I get the following error:
"NotAuthorizedException" Incorrect username or password.
It's ok. But if I set username
to test12345
(non existing user), I get this error:
"UserNotFoundException" User does not exist.
I think telling end users that a username exists or not is not really safe.
Am I wrong? Is it something I did wrong?
I would like to have only the first exception to notice end users that login failed.