问题描述:在使用AWS Cognito的forgotPassword API时,如果用户不存在,返回的响应是“UserNotFoundException”,这个异常是预期的,但是异常消息中包含了一条奇怪的信息“CheckUserExists failed with exception”,这个信息可能导致使用者很困惑。
const AWS = require('aws-sdk');
const Cognito = new AWS.CognitoIdentityServiceProvider({
region: 'YOUR_REGION',
apiVersion: '2016-04-18'
});
const params = {
UserPoolId: 'YOUR_USERPOOL_ID',
ClientId: 'YOUR_APP_CLIENT_ID'
};
async function forgotPasswordRequest(params) => {
try {
const res = await Cognito.forgotPassword(params).promise();
console.log('forgotPassword response:', res);
return res;
} catch (error) {
if (error.code === 'UserNotFoundException') {
console.log('UserNotFoundException:', error.message);
} else {
console.error(error);
}
throw error;
}
}
这样,当用户不存在时,错误信息就不再包括“CheckUserExists failed with exception”这条奇怪的信息了。
上一篇:AWSCognito在添加迁移后返回“未提供电子邮件但电子邮件已验证”
下一篇:AWSCognito在自定义域名下没有正确实现/.well-known/openid-configuration?