本地存储缺少ID令牌,请在更改密码Cognito AWS时对错误进行身份验证 [英] Local storage is missing an ID Token, Please authenticate error while changing password Cognito AWS
问题描述
我正在构建一个应用程序.在该操作中,注册
, Signin
和其他操作都可以正常进行.但是,当我尝试使用以下代码更改密码时,显示为
I am building an application. In that Sign up
, Signin
and other operations are working fine. But, when I try to change password using following code, it says
"Local storage is missing an ID Token, Please authenticate"
代码是:
changePassword(mail: any) {
var that = this;
var userPool = new CognitoUserPool(this.poolData);
var userData: any = {
Username: mail,
Pool: userPool
};
var cognitoUser = new CognitoUser(userData);
// To get the session
cognitoUser.getSession(function (err, session) {
if (err) {
alert(err);
return;
}
var userPool = new CognitoUserPool(that.poolData);
var userData: any = {
Username: mail,
Pool: userPool
};
var cognitoUser = new CognitoUser(userData);
var oldp = prompt('Please input old password ', '');
var newp = prompt('Please input new password ', '');
cognitoUser.changePassword(oldp, newp, function (err, result) {
if (err) {
alert(err.message || JSON.stringify(err));
return;
}
alert("Password successfully changed...");
});
});
}
我不确定这有什么问题.请帮我解决这个问题.
I am not sure what is wrong in this. Please help me solve this.
谢谢...
推荐答案
经过艰苦的努力,我发现每次使用
After so much of struggle, I figured out that I was creating new Cognito user every time using
poolData = {
UserPoolId: "XXXXXXXXXXXXXXXXX",
ClientId: "XXXXXXXXXXXXXXXXXXXXXXXX"
};
userPool: CognitoUserPool = new CognitoUserPool(this.poolData);
因此,每当我这样称呼时,都会创建一个新的认知用户.因此,对此的更改密码无效.
So, whenever I call this, a new cognito-user is created. So, change-password on this was not working.
当我创建一个通用函数来访问 cognitoUser
并在各处使用该函数时,对我来说是可行的.
When I created a common function to access cognitoUser
and using the same everywhere worked for me.
谢谢...
这篇关于本地存储缺少ID令牌,请在更改密码Cognito AWS时对错误进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!