Sha256: abc259d0f1dd205574f64271e9b6221a2a681d2aadf96fe214d72e748342f81a

Contents?: true

Size: 640 Bytes

Versions: 4

Compression:

Stored size: 640 Bytes

Contents

##
# Prepend for Spree::Api::BaseController methods
#
module Spree::Api::BaseController::JsonWebTokens
  def load_user
    return super unless json_web_token.present?

    # rubocop:disable Naming/MemoizedInstanceVariableName
    @current_api_user ||= Spree.user_class.find_by(id: json_web_token['id'])
    # rubocop:enable Naming/MemoizedInstanceVariableName
  end

  def json_web_token
    @json_web_token ||= SolidusJwt.decode(api_key).first
  rescue JWT::DecodeError
    # Allow spree to try and authenticate if we still allow it. Otherwise
    # raise an error
    return if SolidusJwt::Config.allow_spree_api_key

    raise
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus_jwt-1.0.0 app/controllers/spree/api/base_controller/json_web_tokens.rb
solidus_jwt-1.0.0.beta2 app/controllers/spree/api/base_controller/json_web_tokens.rb
solidus_jwt-1.0.0.beta1 app/controllers/spree/api/base_controller/json_web_tokens.rb
solidus_jwt-0.1.0 app/controllers/spree/api/base_controller/json_web_tokens.rb