我正在开发aws-serverless + react应用程序。我的问题是使用aws-amplify进行身份验证。身份验证可以正常进行,但会话不会保留。
SigningIn:
await Auth.signIn(this.state.email, this.state.password)
.then(x => {
console.log(JSON.stringify(x))
})
.catch(e => alert(e.message));响应:
{
"username": "xxxxx",
"pool": {
"userPoolId": "eu-central-1_xxxxx",
"clientId": "xxxxx",
"client": {
"endpoint": "https://cognito-idp.eu-central-1.amazonaws.com/",
"userAgent": "aws-amplify/0.1.x js"
},
"advancedSecurityDataCollectionFlag": true,
"storage": {
"loglevel:webpack-dev-server": "INFO"
}
},
"Session": "xxxxx",
"client": {
"endpoint": "https://cognito-idp.eu-central-1.amazonaws.com/",
"userAgent": "aws-amplify/0.1.x js"
},
"signInUserSession": null,
"authenticationFlowType": "USER_SRP_AUTH",
"storage": {
"loglevel:webpack-dev-server": "INFO"
},
"keyPrefix": "CognitoIdentityServiceProvider.xxxxx",
"userDataKey": "CognitoIdentityServiceProvider.xxxxx.xx@x.pl.userData",
"challengeName": "NEW_PASSWORD_REQUIRED",
"challengeParam": {
"userAttributes": {
"email_verified": "true",
"phone_number_verified": "true",
"phone_number": "xxxxx",
"email": "xx@x.pl"
},
"requiredAttributes": []
}
}在那之后,我让它等待几秒钟。并尝试获取会话数据:
try {
await Auth.currentSession();
}
catch (e) {
alert(e);
}这就产生了错误No current user
我用的是react+typescript+webpack,已经用了两天了。
发布于 2020-06-06 12:22:07
我今天才遇到这个问题。我已经在亚马逊网络服务控制台的(新)用户池中创建了一个新用户,但是在登录之后,会话并没有持久存在(每次我刷新页面时,Auth.currentSession()都会抛出一个错误,指出没有经过身份验证的用户或类似的错误)。
大约一个小时后,我找到了一个解决方案。
当用户需要更新其密码时(您可以在challengeName字段的值中看到这一点),Amplify似乎不会持久化会话。
您应该做的是,当challengeName为NEW_PASSWORD_REQUIRED时,让用户知道他们需要更新密码。
更新我使用的密码
await Auth.completeNewPassword(user, newPassword, {});user来自
const user = await Auth.signIn(email, password);在此之后,会话将被持久化。
https://stackoverflow.com/questions/58157268
复制相似问题