Sha256: e19cff7465704a2efb8a7a754a970bb60020618c698f474d5fac8c748e600cc6

Contents?: true

Size: 1002 Bytes

Versions: 1

Compression:

Stored size: 1002 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

1 entries across 1 versions & 1 rubygems

Version Path
comee_core-0.1.29 app/controllers/comee/core/application_controller.rb