class AuthorizeRequest class << self def user(headers) @user ||= User.find(decoded_auth_token(headers)[:id]) if decoded_auth_token(headers) @user || nil end def decoded_auth_token(headers) @decoded_auth_token ||= JsonWebToken.decode(http_auth_header(headers)) if http_auth_header(headers) end def http_auth_header(headers) return headers['Authorization'].split(' ').last if headers['Authorization'].present? nil end end end