Module: JWTAuthentication::TokenAuthenticatable

Extended by:
ActiveSupport::Concern
Defined in:
lib/jwt_authentication/token_authenticatable.rb

Instance Method Summary collapse

Instance Method Details

#decode_token(token) ⇒ Object



13
14
15
16
17
18
# File 'lib/jwt_authentication/token_authenticatable.rb', line 13

def decode_token(token)
  payload = JWT.decode(token, Rails.application.secrets.secret_key_base)[0]
  Token.new(payload)
rescue
  nil
end

#encode_token(expiration = 24.hours.from_now) ⇒ Object



7
8
9
10
11
# File 'lib/jwt_authentication/token_authenticatable.rb', line 7

def encode_token(expiration = 24.hours.from_now)
  payload = { id: self.id }
  payload[:expiration] = expiration
  JWT.encode(payload, Rails.application.secrets.secret_key_base)
end