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令牌,而让我留下一个空会话却令人困惑。
看着我看到的控制台
答案 0 :(得分:1)
如果调用Auth.signIn
时没有收到错误,请检查user.challengeName
的内容。
const user = await Auth.signIn({
username, // Required, the username
password, // Optional, the password
validationData,
})
如果user.challengeName
是NEW_PASSWORD_REQUIRED
,则必须致电
Auth.completeNewPassword(user, "newPassword");
您可以阅读有关身份验证挑战here的更多信息。