summaryrefslogtreecommitdiff
path: root/app/controllers/authenticated_controller.rb
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-03-03 20:34:06 -0600
committerHombreLaser <sebastian-440@live.com>2023-03-03 20:34:06 -0600
commit41a17f47ae275f8e84de03115e142cc23526bacc (patch)
tree2fb62f78685698a7c55bf5cff8456d24b7a78361 /app/controllers/authenticated_controller.rb
parent094ee717f710ea4cf81d221c5bf9660b805da9b1 (diff)
Añade refactorizaciones
Diffstat (limited to 'app/controllers/authenticated_controller.rb')
-rw-r--r--app/controllers/authenticated_controller.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/controllers/authenticated_controller.rb b/app/controllers/authenticated_controller.rb
index 56be1ad..7098202 100644
--- a/app/controllers/authenticated_controller.rb
+++ b/app/controllers/authenticated_controller.rb
@@ -6,6 +6,23 @@ class AuthenticatedController < ApplicationController
private
+ 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
+
def validate_jwt
return if valid_token