简体   繁体   中英

Rails 6 omniauth working on local but not production (Heroku)

I have a:

  • -rails 6 app
  • -deploy on Heroku
  • -Devise with omniauth both with Facebook and google
  • -On locale omniauth is working as expected
  • -On stagging and production (heroku) i am getting the following error once i select the google (or facebook) with which i want to connect and get redirected to home page without any other action:

Authentication failure: undefined method `bytesize' for #<Hash....

Here is what my links look like:

 <%= link_to t('navbar.loginf'), user_facebook_omniauth_authorize_path,  method: :post, class: "is-fullwidth" %>

<%= link_to t('navbar.loging'), user_google_oauth2_omniauth_authorize_path, method: :post, class: "is-fullwidth" %>

This is omniauth controller:

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
    @user = User.from_omniauth(request.env['omniauth.auth'])

    if @user.persisted?
      sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated
      set_flash_message(:notice, :success, kind: 'Facebook') if is_navigational_format?
    else
      session['devise.facebook_data'] = request.env['omniauth.auth']
      redirect_to new_user_registration_url
    end
  end

  def google_oauth2
    @user = User.from_omniauth(request.env['omniauth.auth'])
    if @user.persisted?
      sign_in_and_redirect @user
      set_flash_message(:notice, :success, kind: 'Google') if is_navigational_format?
    else
      flash[:error] = I18n.t('alert.gge')
      redirect_to new_user_registration_url
    end
  end

  def failure
    redirect_to root_path
  end
end

Find the issue:

-Had to update yarn.lock file (delete the yarn.lock file And run the yarn install commad on terminal it will generate a new yarn.lock )

-This version was different on heroku

"@babel/parser@^7.16.7", "@babel/parser@^7.17.3":

-Google callback call the JS file to hit the action with the params that we are requested.

-So Omniauth need to parse it but its not able to do this because the babel is not parsing it properly and give it to auth_hash method of omniauth.rb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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