简体   繁体   English

通过Turbolinks登录Google+

[英]Google+ sign-in with Turbolinks

I'm building a rails application that makes use of the Turbolinks stuff that comes with Rails 4. I am also trying to use the Google+ sign in button for user authentication. 我正在构建一个利用Rails 4随附的Turbolinks东西的Rails应用程序。我还试图使用Google+登录按钮进行用户身份验证。

I have everything working except in one case: If the user visits more than one page before logging in, the google+ sign in process doesn't work. 除了一种情况,我可以进行所有工作:如果用户在登录之前访问了多个页面,则google +登录过程无法正常工作。 Basically, the Turbolinks magic is breaking the Google+ signin button. 基本上,Turbolinks的魅力打破了Google+登录按钮。 (If the user signs in right away, everything works perfectly) (如果用户立即登录,一切将正常进行)

That said, I can see where the problem seems to be. 也就是说,我可以看到问题出在哪里。 When the google+ js api loads, it attaches a hidden iframe to the body of the html document. 加载Google+ JS API时,它将隐藏的iframe附加到html文档的正文中。 This gets blown away when turbolinks loads another page. 当turbolinks加载另一个页面时,这被吹走了。 I bet this iframe is required for completing the Google+ signin process. 我敢打赌,此iframe是完成Google+登录过程所必需的。

Has anyone crossed a similar bridge? 有人过类似的桥吗? I'm not sure how to prevent turbolinks from removing the iframe. 我不确定如何防止Turbolink删除iframe。 An alternative may be to get the Google+ Api to re-initialize, but nothing like that is mentioned in the Google Plus docs. 另一种选择是让Google+ Api重新初始化,但是Google Plus文档中没有提到类似的东西。

Thanks for any insight! 感谢您的见解!

I had the same issue with the Facebook login button and Bugherd sidebar . 我在Facebook登录按钮Bugherd侧栏 也遇到了同样的问题。
You will need to reload your components on every page:fetch and page:change events. 您将需要在每个page:fetch和page:change事件上重新加载组件。

Here is the pseudo code I use for facebook login: 这是我用于Facebook登录的伪代码:

$(document)
   .on('page:fetch', saveFacebookRoot)
   .on('page:change', restoreFacebookRoot)

I think you can do almost the same think with the Google+ iframe. 我认为您可以使用Google+ iframe进行几乎相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM