From c86a5c9e05b183f10a63fb693c8af1d1d5a52e97 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sun, 26 Feb 2023 20:19:22 -0600 Subject: Refactoriza los create logics --- app/controllers/application_controller.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 857414a..ea108b4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,4 +5,23 @@ class ApplicationController < ActionController::API def logic(permitted_params) @logic = Object.const_get("#{self.class}::#{action_name.camelize}Logic").new(permitted_params) end + + protected + + def current_user_account + return if decoded_token.nil? + + email = decoded_token[0]['data'] + @current_user_account ||= UserAccount.find_by(email:) + end + + def authentication_token + @authentication_token ||= request.headers[:authorization]&.sub(/^Bearer /, '') + end + + def decoded_token + @decoded_token ||= JWT.decode(authentication_token, ENV['HMAC_SECRET_KEY'], true, { algorithm: 'HS512' }) + rescue JWT::ExpiredSignature + @decoded_token = nil + end end -- cgit v1.2.3