Class: JwtSecure::ApiJwtController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/jwt_secure/controllers.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_jwtsecureObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jwt_secure/controllers.rb', line 21

def authenticate_jwtsecure()
  begin 
    payload = JsonWebToken.decode(get_auth_token, @jwtsecure_secret)
    if payload.present?
      @current_user = User.find(payload["user_id"])
    else
      render json: {errors: ["Invalid Token, user not found!"]}, status: :unauthorized
    end
  rescue
    render json: {errors: ["token not found!"]}, status: :unauthorized
  end
end

#get_auth_tokenObject



34
35
36
# File 'lib/jwt_secure/controllers.rb', line 34

def get_auth_token()
  @auth_token ||= cookies.encrypted[@jwtsecure_cookiename]
end