代码之家  ›  专栏  ›  技术社区  ›  Manoj Acharya

AWS Cognito:首次登录管理员创建的用户时出现未知错误

  •  2
  • Manoj Acharya  · 技术社区  · 7 年前

    每当我尝试以状态登录用户时 强制\u密码\u更改 这是我第一次在 ON故障 回调函数。

    code:"UnknownError"
    message:"200"
    name:"UnknownError"
    statusCode:200
    

    当我单击login按钮时,将执行以下函数。

    logInUser({username, password}){
        const p = new Promise((res, rej)=> {
            var authenticationData = {
                Username: username,
                Password: password,
            };
            var authenticationDetails = new AuthenticationDetails(authenticationData);
    
            var userData = {
                Username: username,
                Pool: UserPool
            };
            var cognitoUser = new CognitoUser(userData);
            cognitoUser.authenticateUser(authenticationDetails, {
                onSuccess: function (result) {
                    alert("Success")
                    console.log('access token + ' + result.getAccessToken().getJwtToken());
                    console.log('idToken + ' + result.idToken.jwtToken);
                    res({result})
                },
    
                onFailure: function (err) {
                    console.log("Got an error")
                    console.log(err);
                    rej(err)
                },
            });
        });
        return p;
    }
    
    1 回复  |  直到 7 年前
        1
  •  4
  •   Sean Macfarlane    7 年前

    您需要为authenticateUser所需的newPasswordRequired传入回调。 https://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-identity-user-pools-javascript-example-authenticating-admin-created-user.html

    cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: function (result) {
            res({result})
        },
        onFailure: function (err) {
            rej(err)
        },
        newPasswordRequired: function(userAttributes, requiredAttributes) {
            console.log("User needs new password");
            res({userAttributes, requiredAttributes});
        },
    });