ToolJet/lib/json_web_token.rb
2021-05-03 18:21:10 +05:30

15 lines
359 B
Ruby

class JsonWebToken
class << self
def encode(payload, exp = 30.days.from_now)
payload[:exp] = exp.to_i
JWT.encode(payload, ENV.fetch('SECRET_KEY_BASE'))
end
def decode(token)
body = JWT.decode(token, ENV.fetch('SECRET_KEY_BASE'))[0]
HashWithIndifferentAccess.new body
rescue StandardError
nil
end
end
end