由于某些原因,只有adminConfirmSignUp给出此错误。使用CognitoUser进行身份验证不会出现此错误。两者都配置为相同的用户池和区域。
下面是使用cognitoUser进行身份验证的代码,该代码正在运行:
public async login(req: UserLoginRequest): Promise<object> {
return new Promise<any>(async (resolve, reject) => {
console.log(`This is the req password-----> ${req.password}`)
try {
var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails({
Username: req.emailAddress,
Password: req.password
});
var userData = {
Username: req.emailAddress,
Pool: this.userPool
};
this.cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
await this.authenticateUser(this.cognitoUser, authenticationDetails).then(value=> {
resolve(value)
}).catch(error => {
console.log(`This is the login error catch----> ${JSON.stringify(error)}`)
});
} catch (error) {
console.log(`I entered into catch .......${JSON.stringify(error)}`)
reject(error);
}
});
}
private async authenticateUser(cognitoUser: AmazonCognitoIdentity.CognitoUser, authenticationDetails: AmazonCognitoIdentity.AuthenticationDetails) {
console.log(`Inside authenticate user`);
console.log(`This is the cognitoUser -----> ${JSON.stringify(cognitoUser)} and these are the authentication details-----> ${JSON.stringify(authenticationDetails)}`)
try{
return new Promise<any>(async (resolve, reject) => {
await cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: (result) => {
console.log(`This is the success result ----> ${JSON.stringify(result)}`);
resolve(result)
},
onFailure: (error) => {
console.log(`This is the error being returned in onFailure ----> ${JSON.stringify(error)}`)
resolve(error)
}
})
})
}
catch(error){
rejects(error);
}
}
使用AWS.CognitoIdentityServiceProvider的确认用户不起作用。给出错误,用户池不存在:
private async confirmUser(resetDetails: ResetPassword, cognitoAdmin: AWS.CognitoIdentityServiceProvider) {
console.log(`This is the admin config cognito ----> ${JSON.stringify(cognitoAdmin)}`)
return new Promise<any>(async (resolve,reject)=>{
console.log(`Inside confirm`);
const confirmParams = {
UserPoolId: process.env.COGNITO_USER_POOL_ID!,
Username: resetDetails.emailAddress!
}
console.log(`This is the user pool ID -----> ${confirmParams.UserPoolId} and this is the region----> ${cognitoAdmin.config.region}`);
await cognitoAdmin.adminConfirmSignUp(confirmParams, async (err, data) => {
if (err) {
console.log(`This is the admin user confirm error ---> ${err}`)
reject(err);
}
else {
cognitoAdmin.adminUpdateUserAttributes({
UserAttributes: [{
Name: 'email_verified',
Value: 'true'
}],
UserPoolId: process.env.COGNITO_USER_POOL_ID!,
Username: resetDetails.emailAddress!
}, (err, data) => {
if (err) {
reject(err)
}
else {
resolve(data)
}
}
)
}
})
})
}
这是发送到上述ConfirmUser方法的cognitoAdmin
参数的cognitoAdmin参数详细信息:
var cognitoAdmin = new AWS.CognitoIdentityServiceProvider({ region: process.env.COGNITO_POOL_REGION!});