title: Omniauth authentication - catch the moment when the user gets redirected to google
body: <pre><code># Gemfile
  gem 'omniauth'
  gem 'omniauth-google-oauth2'
  gem 'devise'
  
  # view
  - if user_signed_in?
    Signed in as 
    = current_user.oauth_name
    = button_to('Sign out', destroy_user_session_path, method: :delete)
  - else
    = link_to('Sign in with Google', user_omniauth_authorize_path(:google_oauth2))
  </code></pre>
  
  <p>What's the best way to catch the moment when the user gets redirected to google for authentication? </p>
  
  <p>It could be by "javascript onclick", but I want to catch the moment on the server somehow (if it's possible) because I need to save some variable to the session.</p>