Add support for non-html authenticate_user! responses

This commit is contained in:
Eric Schultz 2021-01-05 16:44:45 -06:00 committed by Eric Schultz
parent 3d92560e7a
commit bdd32643db
2 changed files with 13 additions and 3 deletions

View file

@ -8,15 +8,15 @@ module Controllers::User::Authorization
included do
helper_method :current_role?, :administered_nonprofit
private
def authenticate_user!(type= :html)
reject_with_sign_in unless current_user
def authenticate_user!(msg=nil, type= :html)
reject_with_sign_in(msg, type) unless current_user
end
def reject_with_sign_in(msg=nil, type= :html)
if type == :html
block_with_sign_in(msg)
else
render text: msg, status: :unauthorized
render json: {message:msg}, status: :unauthorized
end
end

View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
#
class DirectUploadsController < ActiveStorage::DirectUploadsController
include Controllers::Nonprofit::Authorization
skip_before_action :verify_authenticity_token, only: [:create]
before_action do
authenticate_user!("You must be logged in to use this", :json)
end
end