Class: JsonWebToken

Inherits:
Object
  • Object
show all
Defined in:
lib/json_web_token.rb

Class Method Summary collapse

Class Method Details

.decode(token) ⇒ Object



7
8
9
10
11
12
# File 'lib/json_web_token.rb', line 7

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

.encode(payload, expiry = 15.minutes.from_now.to_i) ⇒ Object



3
4
5
# File 'lib/json_web_token.rb', line 3

def encode(payload, expiry = 15.minutes.from_now.to_i)
  JWT.encode(payload.merge(exp: expiry), Rails.application.secrets.secret_key_base)
end