Module: SolidusJwt::Spree::Api::BaseControllerDecorator
- Defined in:
- app/decorators/controllers/solidus_jwt/spree/api/base_controller_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #json_web_token ⇒ Object
-
#load_user ⇒ Object
Overrides Solidus.
Class Method Details
.prepended(base) ⇒ Object
7 8 9 10 11 |
# File 'app/decorators/controllers/solidus_jwt/spree/api/base_controller_decorator.rb', line 7 def self.prepended(base) base.rescue_from JWT::DecodeError do render "spree/api/errors/invalid_api_key", status: :unauthorized end end |
Instance Method Details
#json_web_token ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'app/decorators/controllers/solidus_jwt/spree/api/base_controller_decorator.rb', line 25 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 |
#load_user ⇒ Object
Overrides Solidus
17 18 19 20 21 22 23 |
# File 'app/decorators/controllers/solidus_jwt/spree/api/base_controller_decorator.rb', line 17 def load_user return super if json_web_token.blank? # rubocop:disable Naming/MemoizedInstanceVariableName @current_api_user ||= ::Spree.user_class.for_jwt(json_web_token['sub'] || json_web_token['id']) # rubocop:enable Naming/MemoizedInstanceVariableName end |