reactjs - 未处理的拒绝 (TypeError) : user. getSession 不是函数

标签 reactjs aws-amplify

我在我的应用程序中使用 AWS amplify,我使用 google 实现了登录功能。但是登录后,我收到此错误 Unhandled Rejection (TypeError): user.getSession is not a function

我已使用 Auth.federatedSignIn 函数进行登录。

这是我的代码:

       const responseGoogle = async (response) => {
    try {
      setLoading(true);
      const user = {
        name: response.profileObj.name,
        email: response.profileObj.email
      };

      const password = await Auth.forgotPassword(user.email);

      let expires_at = addMilliseconds(new Date(), 3600 * 1000).getTime();

      const result = await Auth.federatedSignIn(
        'google',
        { token: response.tokenId, expires_at },
        user
      );

      console.log(result);
      console.log('heree');

      history.push('/classes/google');
      setLoading(false);
      setUserInfo(loadedUsers, email);
    } catch (error) {
      console.log(error);
      if (error.message !== `Cannot read property 'name' of undefined`) {
        enqueueSnackbar(error.message, { variant: 'error' });
      }
      setLoading(false);
    }
  };

response 是我从 google 得到的响应。

有谁知道我为什么会收到这个错误?感谢任何类型的帮助。谢谢

最佳答案

首先你必须检查所有限制 auth 在你创建 auth 函数时在配置 json 中

第二件事是你必须传递三个参数才能更改密码,例如

  • 用户 是用户 session ,您可以通过获取当前 session token 和身份验证数据来获取它。
  • 旧密码
  • 新密码

关于reactjs - 未处理的拒绝 (TypeError) : user. getSession 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67006996/

相关文章:

ios - 如何在 Objective-C 中设置 Amazon Amplify iOS?

amazon-web-services - AWS Amplify cloudformationparameter.json 如何工作?

reactjs - AWS 因 aws-exports 导致部署失败加剧

git - AWS amplify 不部署最新提交

reactjs - 将用户添加到 Cognito 后刷新 Cognito 访问 token

javascript - 组件 onPress 函数内的渲染按钮显示最后一个 i。 React-Native

javascript - 如何映射来自 REST 调用的响应?

javascript - 如何在 native react 中设置下拉菜单中的默认值

javascript - 将正则表达式字符串 react 为 html

css - 更改 Material-UI 概述的芯片焦点和悬停颜色