4

I have a Rails app where users can sign in / up using Google SSO. I use the gem omniauth-google-oauth2 and One-time Code Flow (Hybrid Authentication). It work in some cases - but not all. It always works when I do a hard refresh of the page / browser.

The pattern I've noticed is that when I see this line in Chrome's JS console it works:

Navigated to http://127.0.0.1:3000/signin 

When Navigated to [..] isn't displayed it doesn't work. My suspicion is that it has something do do with either turbo links or some other caching issue.

I have tried the following to see if it was related to turbo links, but it didn't help:

# Coffeescript file
ready = -> 
  # Google logic and functions

$(document).ready(ready)

Any ideas on what can be causing this issue and how I can solve it?

Anders
  • 2,903
  • 7
  • 58
  • 114
  • You're probably correct regarding turbolinks but to test that I think you'll want `$(document).on('page:load', ready);` after your `$(document).ready(ready)` – frostmatthew Jul 18 '15 at 13:18
  • Thanks @Exupery, the issue I see when I add `$(document).on('page:load', ready);` is that that code inside the `ready = ->` function gets called twice. And it didn't seem to help with my core issue - that the Google SSO doesn't work in all cases for me. – Anders Jul 18 '15 at 13:31
  • @Exupery Minor correction to my previous comment, it doesn't always run twice, when it doesn't run twice it works. But when it runs twice it doesn't. – Anders Jul 18 '15 at 13:38
  • Not sure why it's getting called twice, I have multiple RoR apps that use that workaround and it only gets called once (just double checked one of them). See this [answer](http://stackoverflow.com/a/18770589/903163) and its comments (which explain why it should never result in calling `ready` twice). – frostmatthew Jul 18 '15 at 13:52
  • @Exupery Thanks again. Think I have solved it, and also possibly found the reason for the "double calls". Added it as an answer below. You can maybe take a look at it in action here (if you want :), https://www.brightly.io. – Anders Jul 18 '15 at 15:02

1 Answers1

2

Think I solved it. In my application.js file I had both //= require turbo links and:

//= require jquery.turbolinks

Removing //= require turbo links seems to have helped.

Anders
  • 2,903
  • 7
  • 58
  • 114