CognitoUser会话:成功登录后为null

时间:2020-01-31 04:55:35

标签: amazon-cognito aws-amplify

Auth.signIn({
    username, // Required, the username
    password, // Optional, the password
    validationData, // Optional, a random key-value pair map which can contain any key and will be passed to your PreAuthentication Lambda trigger as-is. It can be used to implement additional validations around authentication
}).then(user => console.log(user))
.catch(err => console.log(err));

所以我正在使用AWS Amplify Auth.signIn

我成功登录并获得了ID令牌,查看了正确的用户名并进行了存储

但是会话为空...

这阻止了我使用... Auth.VerifyCurrentUser

// To initiate the process of verifying the attribute like 'phone_number' or 'email'
Auth.verifyCurrentUserAttribute(attr)
.then(() => {
     console.log('a verification code is sent');
}).catch((e) => {
     console.log('failed with error', e);
});

验证电子邮件后,我需要Auth.VerifyCurrentUser来验证phone_number

为什么它会给我id令牌,而让我留下一个空会话却令人困惑。

Erros

看着我看到的控制台

POST https://cognito-identity.us-east-1.amazonaws.com/ 400

POST https://cognito-idp.us-east-1.amazonaws.com/ 400

1 个答案:

答案 0 :(得分:1)

如果调用Auth.signIn时没有收到错误,请检查user.challengeName的内容。

const user = await Auth.signIn({
    username, // Required, the username
    password, // Optional, the password
    validationData,
})

如果user.challengeNameNEW_PASSWORD_REQUIRED,则必须致电

Auth.completeNewPassword(user, "newPassword");

您可以阅读有关身份验证挑战here的更多信息。