Module: RailsJwtAuth::AuthenticableHelper

Defined in:
app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb

Instance Method Summary collapse

Instance Method Details

#authenticateObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 27

def authenticate
  begin
    payload = RailsJwtAuth::JwtManager.decode_from_request(request).first
    @current_user = RailsJwtAuth.model.from_token_payload(payload)
  rescue JWT::ExpiredSignature, JWT::VerificationError, JWT::DecodeError
    @current_user = nil
  end

  if @current_user&.respond_to? :update_tracked_fields!
    @current_user.update_tracked_fields!(request)
  end
end

#authenticate!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 13

def authenticate!
  begin
    payload = RailsJwtAuth::JwtManager.decode_from_request(request).first
  rescue JWT::ExpiredSignature, JWT::VerificationError, JWT::DecodeError
    unauthorize!
  end

  if !@current_user = RailsJwtAuth.model.from_token_payload(payload)
    unauthorize!
  elsif @current_user.respond_to? :update_tracked_fields!
    @current_user.update_tracked_fields!(request)
  end
end

#current_userObject



5
6
7
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 5

def current_user
  @current_user
end

#signed_in?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 9

def signed_in?
  !current_user.nil?
end

#unauthorize!Object

Raises:



40
41
42
# File 'app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb', line 40

def unauthorize!
  raise NotAuthorized
end