Module: RailsJwtAuth::AuthenticableHelper
- Included in:
- InvitationsController, ProfilesController, SessionsController
- Defined in:
- app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
- #authenticate! ⇒ Object
- #current_user ⇒ Object
- #get_jwt_from_request ⇒ Object
- #jwt_payload ⇒ Object
- #signed_in? ⇒ Boolean
- #track_request ⇒ Object
- #unauthorize! ⇒ Object
Instance Method Details
#authenticate ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 35 def authenticate begin @jwt_payload = RailsJwtAuth::JwtManager.decode(get_jwt_from_request).first @current_user = RailsJwtAuth.model.from_token_payload(@jwt_payload) rescue JWT::ExpiredSignature, JWT::VerificationError, JWT::DecodeError @current_user = nil end track_request end |
#authenticate! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 21 def authenticate! begin @jwt_payload = RailsJwtAuth::JwtManager.decode(get_jwt_from_request).first rescue JWT::ExpiredSignature, JWT::VerificationError, JWT::DecodeError end if !@current_user = RailsJwtAuth.model.from_token_payload(@jwt_payload) else track_request end end |
#current_user ⇒ Object
5 6 7 |
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 5 def current_user @current_user end |
#get_jwt_from_request ⇒ Object
17 18 19 |
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 17 def get_jwt_from_request request.env['HTTP_AUTHORIZATION']&.split&.last end |
#jwt_payload ⇒ Object
9 10 11 |
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 9 def jwt_payload @jwt_payload end |
#signed_in? ⇒ Boolean
13 14 15 |
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 13 def signed_in? !current_user.nil? end |
#track_request ⇒ Object
50 51 52 53 54 |
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 50 def track_request if @current_user&.respond_to? :update_tracked_request_info @current_user.update_tracked_request_info(request) end end |
#unauthorize! ⇒ Object
46 47 48 |
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 46 def raise NotAuthorized end |