Class: SolidusJwt::Token
- Inherits:
-
BaseRecord
- Object
- BaseRecord
- SolidusJwt::Token
- Defined in:
- app/models/solidus_jwt/token.rb
Class Method Summary collapse
-
.honor?(token) ⇒ Boolean
Whether to honor a token or not.
-
.invalidate(user) ⇒ Object
Set all non expired refresh tokens to inactive.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
Whether the token is expired.
-
#honor? ⇒ Boolean
Whether the token should be honored.
Methods inherited from BaseRecord
Class Method Details
.honor?(token) ⇒ Boolean
Whether to honor a token or not.
42 43 44 |
# File 'app/models/solidus_jwt/token.rb', line 42 def self.honor?(token) non_expired.where(active: true).find_by(token: token).present? end |
.invalidate(user) ⇒ Object
Set all non expired refresh tokens to inactive
30 31 32 33 34 35 36 |
# File 'app/models/solidus_jwt/token.rb', line 30 def self.invalidate(user) # rubocop:disable Rails/SkipsModelValidations non_expired. where(user_id: user.to_param). update_all(active: false) # rubocop:enable Rails/SkipsModelValidations end |
Instance Method Details
#expired? ⇒ Boolean
Whether the token is expired
59 60 61 |
# File 'app/models/solidus_jwt/token.rb', line 59 def expired? created_at < SolidusJwt::Config.refresh_expiration.seconds.ago end |
#honor? ⇒ Boolean
Whether the token should be honored.
50 51 52 |
# File 'app/models/solidus_jwt/token.rb', line 50 def honor? active? && !expired? end |