我有一个简单的devise和devise-jwt的rails应用程序。我有登录/注销等所有工作与User作为我唯一的作用域。但是我无法让gem在我登录后更新模型上的jti属性。
我希望gem会自动执行此操作,但它从不更新jti。
class User < ApplicationRecord
include Devise::JWT::RevocationStrategies::JTIMatcher
devise :database_authenticatable,
:recoverable, :trackable, :validatable,
:jwt_authenticatable, jwt_revocation_strategy: self
def jwt_payload
super.merge({ custom: 'data' })
end在我的用户迁移中,我使用了索引为add_index :users, :jti, unique: true的适当的t.string :jti。
我必须手动绑定登录回调才能更新jti吗?(模型中包含的Devise::JWT::RevocationStrategies::JTIMatcher看起来很奇怪)
发布于 2018-06-01 14:37:34
我让它手动工作的。必须进行更新:
# user.rb
def jwt_payload
self.jti = self.class.generate_jti
self.save
# super isn't doing anything useful, but if the gem updates i'll want it to be safe
super.merge({
jti: self.jti,
usr: self.id,
...
})
end我读了https://github.com/waiting-for-dev/devise-jwt/blob/958cab34287f9985aacc84fedbbb3ea508f6c3b2/lib/devise/jwt/revocation_strategies/jti_matcher.rb,但不明白为什么调用super会返回{ jti: nil}
会很乐意看到更好的方法。
https://stackoverflow.com/questions/50637167
复制相似问题