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