I'm trying to change current password my solution is
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')
}
});
};
the cognito session is valid for one hour so when I try to getSession the session is null and reject with Error: Local storage is missing an ID Token, Please authenticate