CognitoUser Session:成功登录后为 null

Jay*_*Jay 1 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));
Run Code Online (Sandbox Code Playgroud)

所以我使用 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);
});
Run Code Online (Sandbox Code Playgroud)

我需要 Auth.VerifyCurrentUser 在验证电子邮件后验证电话号码

为什么它给我 id-tokens 并留下一个 null 会话,这很令人困惑。

埃罗斯

看着控制台我看到

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

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

小智 5

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

const user = await Auth.signIn({
    username, // Required, the username
    password, // Optional, the password
    validationData,
})
Run Code Online (Sandbox Code Playgroud)

如果user.challengeName是的话NEW_PASSWORD_REQUIRED你必须打电话

Auth.completeNewPassword(user, "newPassword");
Run Code Online (Sandbox Code Playgroud)

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