我正在尝试更改当前密码我的解决方案是
exports.changePassword = async function (body) {
return new Promise((resolve, reject) => {
const userData = {
Username: body.email,
Pool: userPool
};
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
if (cognitoUser) {
cognitoUser.getSession(function (err, session) {
console.log(" ~ file: auth.service.js ~ line 283 ~ session", session)
if (err) {
console.log(" ~ file: auth.service.js ~ line 284 ~ err", err)
reject(err);
} else {
cognitoUser.changePassword(body.currentPassword, body.newPassword, function (
err,
res
) {
if (err) {
console.log(" ~ file: auth.service.js ~ line 291 ~ err", err)
reject(err);
} else {
resolve(res);
}
});
}
});
} else {
reject('User is not authenticated')
}
});
};
cognito 会话有效期为一小时,因此当我尝试 getSession 会话为 null 并拒绝时出现 错误:本地存储缺少 ID 令牌,请进行身份验证