gpt4 book ai didi

ruby-on-rails - 用户注册 Facebook 时如何修复空白电子邮件错误(通过 Omniauth)

转载 作者:行者123 更新时间:2023-12-04 19:55:09 26 4
gpt4 key购买 nike

我允许在我的 Rails 网站上进行 Facebook 身份验证,并为此使用 Omniauth。我最近在生产中收到以下错误:

ActiveRecord::RecordInvalid: Validation failed: Email can't be blank, Email is invalid

通常 Facebook 注册工作正常,那么什么会导致这个特定错误?下面是我使用 Omniauth 创建用户的代码。

def self.create_from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.email = auth[:info][:email]
user.password = SecureRandom.urlsafe_base64(n=10)
user.save!
end
end

最佳答案

其实关于这个issue in the omniauth-facebook repo已经有很多讨论了.

我认为用户TeamRainless is the one who got closest to the answer:

Some users have supplied a phone number which facebook uses as it's main authentication method instead of the email address. I believe the phone number is then encrypted and that becomes what the email address would normally be.

此问题的唯一解决方案是将用户重定向到将完成注册过程的表单。查看Railscasts OmniAuth Part 2 episode关于如何做到这一点。

关于ruby-on-rails - 用户注册 Facebook 时如何修复空白电子邮件错误(通过 Omniauth),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18384558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com