我在我的应用程序中使用 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/