Module: JWT::Auth::Authentication

Defined in:
lib/jwt/auth/authentication.rb

Overview

Controller methods

Instance Method Summary collapse

Instance Method Details

#add_token_to_responseObject

Add JWT header to response



31
32
33
34
35
# File 'lib/jwt/auth/authentication.rb', line 31

def add_token_to_response
  return unless token&.valid?
  token.renew!
  response.headers['Authorization'] = "Bearer #{token.to_jwt}"
end

#authenticate_userObject

Authenticate a request



21
22
23
24
25
26
# File 'lib/jwt/auth/authentication.rb', line 21

def authenticate_user
  return head :unauthorized unless token&.valid?

  # Regenerate token (renews expiration date)
  add_token_to_response
end

#current_userObject

Current user helper



14
15
16
# File 'lib/jwt/auth/authentication.rb', line 14

def current_user
  token&.subject
end