Search code examples
javascriptruby-on-railsrubygoogle-oauthturbolinks

Rails / JS - G+ signin button only works after page reload in some cases


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?


Solution

  • 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.