reactjs - 通过使用 Cognito 和 Amplify 发送新的 SMS MFA 来更新会话
问题描述
我有一个带有 Amplify 的 React 应用程序,它使用 AWS Cognito 池正确发送 SMS 以进行用户验证和身份验证。
登录顺利,用户收到短信。
当我尝试为需要很长时间才能进入 OTP 的用户实施“发送新短信”功能时,问题就出现了,并且会话在他们身上到期(3 分钟)。
以下是我的正常登录功能:
async componentDidMount() {
const username = "yyy";
const password = "zzz";
user = await Auth.signIn(username, password);
const { challengeName } = user;
console.log(user);
if (!challengeName) {
const { history } = this.props;
history.push("/", { err: "No current user" });
}
}
这是我的“发送新短信”功能:
resendConfirmationCode = async (e) => {
try {
await Auth.resendSignUp(this.state.username);
console.log("code resent successfully");
this.resetTimer();
} catch (err) {
console.log("error resending code: ", err);
}
};
这确实会发送另一条短信,但我会收到与第一条短信相同的错误消息:
"NotAuthorizedException", message: "Invalid session for the user, session is expired."
我也尝试刷新会话,我收到一条新短信,但它会导致相同的错误消息:
testingSessionTwo = async (e) => {
try {
const cognitoUser = await Auth.currentAuthenticatedUser();
const currentSession = cognitoUser.signInUserSession;
cognitoUser.refreshSession(currentSession.refreshToken, (err, session) => {
Auth.signOut();
const username = "sss";
const password = "xxx";
Auth.signIn(username, password);
console.log(session);
});
} catch (e) {
// whatever
}
};
我在这里想念什么?
解决方案
推荐阅读
- php - 传递数组以在 Codeigniter 中查看
- html - 仅使用 css 和 html 激活的两个或多个选项卡部分
- c# - 隐藏 ListView Xamarin 表单的复杂问题
- javascript - 如何修复来自注册为“被动”的侦听器对“touchmove”事件的调用“preventDefault ()”被忽略。'
- javascript - 使用新对象中的值更新原始对象中的值,如果不存在则将值设置为 0
- laravel - 在 Laravel 的 update() 中调整我的函数 store()
- reactjs - 如何将组件返回到 ag-grid cellRenderer
- python - 如何从json中提取数据
- php - Netsuite PHP Toolkit - 限制已保存搜索中的返回字段
- php - 如何检查文本变量是否为 null、false 或小于 0?