Sha256: 1dcfdfe5082b14512e61b2088fcb0fe5c5e90becbd74396e47f0cc64a9d9d66a

Contents?: true

Size: 861 Bytes

Versions: 6

Compression:

Stored size: 861 Bytes

Contents

# frozen_string_literal: true

module DeviseJwtAuth::Concerns::UserOmniauthCallbacks
  extend ActiveSupport::Concern

  included do
    validates :email, presence: true, if: :email_provider?
    validates :email,
              devise_jwt_auth_email: true,
              allow_nil: true,
              allow_blank: true,
              if: :email_provider?

    validates_presence_of :uid, unless: :email_provider?

    # only validate unique emails among email registration users
    validates :email,
              uniqueness: { case_sensitive: false, scope: :provider },
              on: :create,
              if: :email_provider?

    # keep uid in sync with email
    before_save :sync_uid
    before_create :sync_uid
  end

  protected

  def email_provider?
    provider == 'email'
  end

  def sync_uid
    self.uid = email if email_provider?
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
devise_jwt_auth-0.4.1 app/models/devise_jwt_auth/concerns/user_omniauth_callbacks.rb
devise_jwt_auth-0.4.0 app/models/devise_jwt_auth/concerns/user_omniauth_callbacks.rb
devise_jwt_auth-0.3.0 app/models/devise_jwt_auth/concerns/user_omniauth_callbacks.rb
devise_jwt_auth-0.2.0 app/models/devise_jwt_auth/concerns/user_omniauth_callbacks.rb
devise_jwt_auth-0.1.7 app/models/devise_jwt_auth/concerns/user_omniauth_callbacks.rb
devise_jwt_auth-0.1.6 app/models/devise_jwt_auth/concerns/user_omniauth_callbacks.rb