Sha256: 768159876c4949ef9506e4ce4bf2d0efb9aba06995f65aad05889fb39a378739

Contents?: true

Size: 564 Bytes

Versions: 1

Compression:

Stored size: 564 Bytes

Contents

Spree::Api::BaseController.class_eval do
  before_action :check_device

  private

  def check_device
    return unless current_api_user
    return unless mobile?

    device_uid = request.headers['Device-Uid']
    user_device = device_service.find_user_device(current_api_user, device_uid)

    user_device.touch && return if user_device.present? # rubocop:disable Rails/SkipsModelValidations
    raise CanCan::AccessDenied
  end

  def mobile?
    request.headers['X-OS'] =~ /iOS|Android/i
  end

  def device_service
    Spree::DeviceService.instance
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree_devices-1.2.0 app/controllers/spree/api/base_controller_decorator.rb