簡體   English   中英

Rails 6 omniauth 在本地工作但不在生產環境 (Heroku)

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

我有一個:

  • -rails 6 應用程序
  • -部署在 Heroku
  • -使用 Facebook 和谷歌設計 omniauth
  • -On locale omniauth 按預期工作
  • - 在暫存和生產 (heroku) 上,一旦我想連接到 select 谷歌(或 facebook)並在沒有任何其他操作的情況下重定向到主頁,我就會收到以下錯誤:

身份驗證失敗:#<Hash.... 的未定義方法“bytesize”...

這是我的鏈接的樣子:

 <%= 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" %>

這是 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

查找問題:

-必須更新 yarn.lock 文件(刪除 yarn.lock 文件並在終端上運行 yarn install 命令,它將生成一個新的 yarn.lock )

-此版本在 heroku 上有所不同

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

-Google 回調調用 JS 文件以使用我們請求的參數點擊操作。

- 所以 Omniauth 需要解析它但它不能這樣做,因為 babel 沒有正確解析它並將它交給 omniauth.rb 的 auth_hash 方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM