Sha256: 170b7413ac0f09ad21d20fc3f7449f1064c8b333b4822ce3f50b5bf2f3ad972a
Contents?: true
Size: 1013 Bytes
Versions: 45
Compression:
Stored size: 1013 Bytes
Contents
module Ecom module Core class ApplicationController < ActionController::API before_action :authenticate def logged_in? !current_user.nil? end def current_user return unless auth_present? user = User.find(auth['id']) @current_user ||= user if user end private def authenticate render json: { error: 'Unauthorized' }, status: 401 unless logged_in? end def token return nil if request.env['HTTP_AUTHORIZATION'].nil? request.env['HTTP_AUTHORIZATION'].scan(/Bearer (.*)$/).flatten.last end def auth TokenAuthService.decode(token) end def auth_present? !token.nil? end def generate_error_message(entity) value = entity.errors.details.first[1][0][:value] field = entity.errors.keys[0] message = entity.errors.values[0][0] entity.errors.full_message(field, "'#{value}' #{message}") end end end end
Version data entries
45 entries across 45 versions & 1 rubygems