Sha256: 2db4231cb74076e521d7083d6978a26ca4e2af5cbe93e8f7c2a14a8cff0ee62a

Contents?: true

Size: 964 Bytes

Versions: 19

Compression:

Stored size: 964 Bytes

Contents

module Comee
  module Core
    class ApplicationController < ActionController::API
      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

19 entries across 19 versions & 1 rubygems

Version Path
comee_core-0.1.28 app/controllers/comee/core/application_controller.rb
comee_core-0.1.27 app/controllers/comee/core/application_controller.rb
comee_core-0.1.26 app/controllers/comee/core/application_controller.rb
comee_core-0.1.25 app/controllers/comee/core/application_controller.rb
comee_core-0.1.24 app/controllers/comee/core/application_controller.rb
comee_core-0.1.23 app/controllers/comee/core/application_controller.rb
comee_core-0.1.22 app/controllers/comee/core/application_controller.rb
comee_core-0.1.21 app/controllers/comee/core/application_controller.rb
comee_core-0.1.20 app/controllers/comee/core/application_controller.rb
comee_core-0.1.19 app/controllers/comee/core/application_controller.rb
comee_core-0.1.18 app/controllers/comee/core/application_controller.rb
comee_core-0.1.17 app/controllers/comee/core/application_controller.rb
comee_core-0.1.16 app/controllers/comee/core/application_controller.rb
comee_core-0.1.15 app/controllers/comee/core/application_controller.rb
comee_core-0.1.14 app/controllers/comee/core/application_controller.rb
comee_core-0.1.13 app/controllers/comee/core/application_controller.rb
comee_core-0.1.12 app/controllers/comee/core/application_controller.rb
comee_core-0.1.11 app/controllers/comee/core/application_controller.rb
comee_core-0.1.10 app/controllers/comee/core/application_controller.rb