Sha256: 14c29c2d625ef8ee178680b950a1dfcfdf9464e4fe1abcc0089a4d98c0bb934e

Contents?: true

Size: 1003 Bytes

Versions: 65

Compression:

Stored size: 1003 Bytes

Contents

module Comee
  module Core
    class ApplicationController < ActionController::API
      include Comee::Core::Pagination

      before_action :authenticate

      def current_user
        return if token.nil?

        user = User.find(auth["id"])
        @current_user ||= user
      end

      def authenticate
        render json: {error: "Unauthorized"}, status: 401 if current_user.nil?
      end

      # In case we want to disable bullet for specific controller actions
      def skip_bullet
        previous_value = Bullet.enable?
        Bullet.enable = false
        yield
      ensure
        Bullet.enable = previous_value
      end

      private

      def serialize(data)
        ActiveModelSerializers::SerializableResource.new(data)
      end

      def token
        return nil if request.env["HTTP_AUTHORIZATION"].nil?

        request.env["HTTP_AUTHORIZATION"].scan(/Bearer (.*)$/).flatten.last
      end

      def auth
        TokenService.decode(token)
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
comee_core-0.1.51 app/controllers/comee/core/application_controller.rb
comee_core-0.1.50 app/controllers/comee/core/application_controller.rb
comee_core-0.1.49 app/controllers/comee/core/application_controller.rb
comee_core-0.1.48 app/controllers/comee/core/application_controller.rb
comee_core-0.1.47 app/controllers/comee/core/application_controller.rb
comee_core-0.1.46 app/controllers/comee/core/application_controller.rb
comee_core-0.1.45 app/controllers/comee/core/application_controller.rb
comee_core-0.1.45.pre3 app/controllers/comee/core/application_controller.rb
comee_core-0.1.45.pre2 app/controllers/comee/core/application_controller.rb
comee_core-0.1.45.pre app/controllers/comee/core/application_controller.rb
comee_core-0.1.44 app/controllers/comee/core/application_controller.rb
comee_core-0.1.43 app/controllers/comee/core/application_controller.rb
comee_core-0.1.42 app/controllers/comee/core/application_controller.rb
comee_core-0.1.41 app/controllers/comee/core/application_controller.rb
comee_core-0.1.40 app/controllers/comee/core/application_controller.rb
comee_core-0.1.39 app/controllers/comee/core/application_controller.rb
comee_core-0.1.38 app/controllers/comee/core/application_controller.rb
comee_core-0.1.37 app/controllers/comee/core/application_controller.rb
comee_core-0.1.36 app/controllers/comee/core/application_controller.rb
comee_core-0.1.35 app/controllers/comee/core/application_controller.rb