Sha256: 8c9a00fde169f682c97a9cc9e743036f4d5668d379733768ef0606b72f061e61

Contents?: true

Size: 599 Bytes

Versions: 45

Compression:

Stored size: 599 Bytes

Contents

# frozen_string_literal: true

module Ibrain
  module Extentions
    class SessionRequired < GraphQL::Schema::FieldExtension
      def resolve(object:, arguments:, **rest)
        raise ActionController::InvalidAuthenticityToken, I18n.t('ibrain.errors.session.invalid_session') if is_invalid_session(object)

        # yield the current time as `memo`
        yield(object, arguments, rest)
      end

      private

      def is_invalid_session(object)
        object.try(:context).try(:fetch, :current_user, nil).blank? && options.try(:fetch, :session_required, false)
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
ibrain-core-0.5.13 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.5.12 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.5.10 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.5.9 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.5.8 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.5.7 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.5.6 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.5.5 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.5.4 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.5.3 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.5.2 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.5.1 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.5.0 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.4.8 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.4.7 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.4.5 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.4.4 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.4.3 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.4.2 app/graphql/ibrain/extentions/session_required.rb
ibrain-core-0.4.1 app/graphql/ibrain/extentions/session_required.rb