![](/img/trans.png)
[英]User authentication with Devise-jwt in Ruby On Rails as backend and Vuejs as frontend
[英]Rails devise-jwt gem is not updating jti in the user after login?
我有一個帶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
在我的用戶遷移中,我有正確的t.string :jti
,索引為add_index :users, :jti, unique: true
。
我是否必須手動綁定登錄回調以更新jti? (對於模型中包含的Devise::JWT::RevocationStrategies::JTIMatcher
似乎很奇怪)
我讓它手動工作。 不得不進行更新:
# 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}
?
希望看到更好的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.