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.91 app/controllers/comee/core/application_controller.rb
comee_core-0.1.90 app/controllers/comee/core/application_controller.rb
comee_core-0.1.89 app/controllers/comee/core/application_controller.rb
comee_core-0.1.88 app/controllers/comee/core/application_controller.rb
comee_core-0.1.87 app/controllers/comee/core/application_controller.rb
comee_core-0.1.86 app/controllers/comee/core/application_controller.rb
comee_core-0.1.85 app/controllers/comee/core/application_controller.rb
comee_core-0.1.84 app/controllers/comee/core/application_controller.rb
comee_core-0.1.83 app/controllers/comee/core/application_controller.rb
comee_core-0.1.82 app/controllers/comee/core/application_controller.rb
comee_core-0.1.81 app/controllers/comee/core/application_controller.rb
comee_core-0.1.80 app/controllers/comee/core/application_controller.rb
comee_core-0.1.79 app/controllers/comee/core/application_controller.rb
comee_core-0.1.78 app/controllers/comee/core/application_controller.rb
comee_core-0.1.77 app/controllers/comee/core/application_controller.rb
comee_core-0.1.76 app/controllers/comee/core/application_controller.rb
comee_core-0.1.75 app/controllers/comee/core/application_controller.rb
comee_core-0.1.74 app/controllers/comee/core/application_controller.rb
comee_core-0.1.73 app/controllers/comee/core/application_controller.rb
comee_core-0.1.72 app/controllers/comee/core/application_controller.rb