Rails 6 omniauth在本地工作,但不在生产(Heroku)



我有一个:

  • -rails 6应用程序
  • -在Heroku上部署
  • -与脸书和谷歌一起设计omnauth
  • -在区域设置上omniauth按预期工作
  • -在stagging和production(heroku(上,一旦我选择了我想连接的谷歌(或脸书(,并在没有任何其他操作的情况下重定向到主页,我就会收到以下错误:

身份验证失败!#<的未定义方法"字节大小";哈希:。。。

以下是我的链接:

<%= 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控制器:

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.loke文件并在终端上运行yarn安装命令,它将生成一个新的yarn.lok(

-这个版本与heroku 不同

"babel/解析器@^7.16.7"babel/解析器@^7.17.3":

-谷歌回调调用JS文件,用我们请求的参数执行操作。

-因此Omniauth需要解析它,但它无法做到这一点,因为babel没有正确解析它,并将其交给Omniauth.rb 的auth_hash方法

最新更新