Skip to content
This repository was archived by the owner on Nov 7, 2023. It is now read-only.

Commit 2fed895

Browse files
authored
Fix callback if migrations fails (lynndylanhurley#1502)
1 parent 7806104 commit 2fed895

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ module DeviseTokenAuth::Concerns::UserOmniauthCallbacks
44
extend ActiveSupport::Concern
55

66
included do
7-
validates :email, presence: true,if: :email_provider?
8-
validates :email, :devise_token_auth_email => true, allow_nil: true, allow_blank: true, if: :email_provider?
9-
validates_presence_of :uid, unless: :email_provider?
7+
validates :email, presence: true, if: lambda { uid_and_provider_defined? && email_provider? }
8+
validates :email, :devise_token_auth_email => true, allow_nil: true, allow_blank: true, if: lambda { uid_and_provider_defined? && email_provider? }
9+
validates_presence_of :uid, if: lambda { uid_and_provider_defined? && !email_provider? }
1010

1111
# only validate unique emails among email registration users
12-
validates :email, uniqueness: { case_sensitive: false, scope: :provider }, on: :create, if: :email_provider?
12+
validates :email, uniqueness: { case_sensitive: false, scope: :provider }, on: :create, if: lambda { uid_and_provider_defined? && email_provider? }
1313

1414
# keep uid in sync with email
1515
before_save :sync_uid
@@ -18,6 +18,10 @@ module DeviseTokenAuth::Concerns::UserOmniauthCallbacks
1818

1919
protected
2020

21+
def uid_and_provider_defined?
22+
defined?(provider) && defined?(uid)
23+
end
24+
2125
def email_provider?
2226
provider == 'email'
2327
end
@@ -26,6 +30,6 @@ def sync_uid
2630
unless self.new_record?
2731
return if devise_modules.include?(:confirmable) && !@bypass_confirmation_postpone && postpone_email_change?
2832
end
29-
self.uid = email if email_provider?
33+
self.uid = email if uid_and_provider_defined? && email_provider?
3034
end
3135
end

0 commit comments

Comments
 (0)