ToolJet/lib/json_web_token.rb

16 lines
359 B
Ruby
Raw Normal View History

2021-03-31 16:18:42 +00:00
class JsonWebToken
2021-04-29 06:41:23 +00:00
class << self
2021-05-03 12:51:10 +00:00
def encode(payload, exp = 30.days.from_now)
2021-04-29 06:41:23 +00:00
payload[:exp] = exp.to_i
JWT.encode(payload, ENV.fetch('SECRET_KEY_BASE'))
2021-03-31 16:18:42 +00:00
end
2021-04-29 06:41:23 +00:00
def decode(token)
body = JWT.decode(token, ENV.fetch('SECRET_KEY_BASE'))[0]
HashWithIndifferentAccess.new body
rescue StandardError
nil
end
end
end