ionic3 - 用户在 AWS 用户池中更改密码时未通过身份验证
解决方案
嗨,我也为此苦苦挣扎,终于得到了这个解决方案。
您应该获得经过身份验证的用户
export const GetAuthenticatedUser = () => {
const userPool = new CognitoUserPool({
UserPoolId: process.env.OGNITO_POOL_ID,
ClientId: process.env.COGNITO_CLIENT_ID
});
return userPool.getCurrentUser();
};
然后你应该调用 getSession() 方法并尝试在其回调中更改密码,否则它不起作用。
export const ChangePassword = (data) => {
return new Promise((resolve, reject) => {
const currentUser = GetAuthenticatedUser();
if (currentUser) {
currentUser.getSession(function (err, session) {
if (err) {
reject(err);
} else {
currentUser.changePassword(data.old_password, data.password, function (
err,
res
) {
if (err) {
reject(GetCognitoError(err.code + '_ChangePassword'));
} else {
resolve(res);
}
});
}
});
} else {
reject('User is not authenticated')
}
});
};
推荐阅读
- r - R用粘贴计算if条件
- vue.js - 如何删除绑定到匿名函数的侦听器?
- c - 我如何用 CodeBlock 解决这个简单的问题?
- iphone - UITextView 文本块被切断
- python - Python:复制的列表会不断更改所有其他列表中的元素,尽管使用了 list()、copy() 等
- python - Python中的多处理-尝试压缩图像在线程中出现异常
- amazon-web-services - 如何在应用程序路径下设置独立的wiremock服务器
- reactjs - 如何在 React Native 中将项目放置在一个圆圈上
- sql - 如何在sql中根据当前会计年度的特定列过滤数据
- python - python opencv DTree 模型:train() 以 std::length_error 终止