I am using devise and devise-jwt for my ror api. I would like to let know the user (by api call) if the user bearer token sent is revoked or not.
I made this route:
def user_token_revoked
decoder = JWT::Decode.new(
request.headers['Authorization'].split(' ')[1],
'GENERATED_TOKEN',
nil,
nil
)
decoded = decoder.decode_segments
user = User.find_by_id(decoded[0]['sub']) # get id user from decoded token
render json: user.jwt_revoked?(decoded), status: :ok
end
But it produces me this error: #<NoMethodError: undefined method `jwt_revoked?' for #User:0x0000558992eb9b98>
I am using this jwt_revocation_strategy: JwtBlacklist in my model:
class JwtBlacklist < ApplicationRecord
include Devise::JWT::RevocationStrategies::Denylist
self.table_name = 'jwt_blacklists'
end
How to call jwt_revoked? function ??
Thanks
jwt_revoked?
is part of the Devise::JWT::RevocationStrategies::Denylist
module. So you'll need to call JwtBlacklist
model
JwtBlacklist.jwt_revoked?(decoded, user)