在设置并运行我自己的客户端ID后,我将完成登录过程并在弹出窗口中选择所需的Google帐户。
选择此选项后,登录失败,控制台中的错误为:
err = {error: "popup_closed_by_user"}
任何人都可以帮我解决这个问题
如果您正在使用端口测试localhost,那么我们应该在google开发者控制台上的add port number
上授权的JavaScript起源部分,如下所示
希望这能解决问题。
当我想使用angular4-social-login登录时,即使我遇到同样的问题。这是因为浏览器中的cookie和弹出设置。它可以在IE中正常运行而不会出错。在Chrome设置中,转到更改Cookie设置中的内容设置并允许弹出窗口。然后清除缓存并重新加载。该应用程序。
加载脚本后('//apis.google.com/js/platform.js'),在DOM中也会插入iframe,例如:
<body>
...
<iframe aria-hidden="true" id="ssIFrame_google" sandbox="allow-scripts allow-same-origin" src="https://accounts.google.com/o/oauth2/iframe#origin=http%3A%2F%2Flocalhost%3A4200&rpcToken=902946799.4541115&clearCache=1" style="position: absolute; width: 1px; height: 1px; left: -9999px; display: none;"></iframe>
</body>
起初,我不明白谷歌为什么会这样做,所以我刚刚删除了这个元素:
const iframeElem = document.getElementById('ssIFrame_google');
if (iframeElem) {
iframeElem.remove();
}
但是当我到达处理成功身份验证响应的阶段时,我遇到了您所描述的错误:popup_closed_by_user。 当我注释掉我的代码以删除iframe时 - 登录成功。
- 我可以假设您的浏览器会过滤内容并删除此iframe。
更改端口号并再次运行应用程序。要更改端口号,您需要更新package.json
文件下的端口号:
"scripts": {
"start": "set PORT=3006 && react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
注意:此处端口号更改为3006。
现在,使用npm start
运行应用程序。