How to allow my user to reset their password on Cognito User Pools?

后端 未结 3 1891
难免孤独
难免孤独 2021-02-05 03:47

So in my app I obviously want to provide the means for users to reset their passwords. The issue I\'m having though is that the new documentation for User Pools is pretty ambigu

3条回答
  •  清歌不尽
    2021-02-05 04:17

    I had this same issue. Was able to work through it by using confirmPassword() in the following way.

    //validation of input from form
    req.checkBody('email', 'Username is required').notEmpty();
    req.checkBody('password', 'Password is required').notEmpty();
    req.checkBody('confirmationcode', 'Confirmation Code is required').notEmpty();
    
    
    var confirmationCode = req.body.confirmationcode;
    var password = req.body.password;
    var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
    
    
    var userData = {
        Username: req.body.email,
        Pool: userPool
    };
    var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
    
    cognitoUser.confirmPassword(confirmationCode, password, {
        onFailure(err) {
            console.log(err);
        },
        onSuccess() {
            console.log("Success");
        },
    });
    

提交回复
热议问题