Module: Tokenable::Authable

Extended by:
ActiveSupport::Concern
Included in:
TokensController
Defined in:
lib/tokenable/authable.rb

Instance Method Summary collapse

Instance Method Details

#current_userObject



16
17
18
19
20
# File 'lib/tokenable/authable.rb', line 16

def current_user
  @current_user ||= user_class.find_by(id: jwt_user_id)
rescue Tokenable::Unauthorized
  nil
end

#require_tokenable_user!Object



22
23
24
25
26
# File 'lib/tokenable/authable.rb', line 22

def require_tokenable_user!
  raise Tokenable::Unauthorized, 'User not found in JWT token' unless jwt_user_id
  raise Tokenable::Unauthorized, 'User is not signed in' unless user_signed_in?
  raise Tokenable::Unauthorized, 'Token verifier is invalid' unless valid_token?
end

#user_signed_in?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/tokenable/authable.rb', line 12

def user_signed_in?
  current_user.present?
end